home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 4
/
Gold Medal Software - Volume 4 (Gold Medal) (1994).iso
/
os2
/
fbar14.arj
/
FILEBAR.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-12
|
149KB
|
3,014 lines
////////////////////////////////////////////////////////////////////////////////
//
// FileBar
//
// OS/2 Application Launch Facility and WPS Shell Replacement
// Version 1.4
//
// Written By Eric A. Wolf
// Copyright (C) 1994 - All Rights Reserved
//
// This source code may be used for reference ONLY! It is provided AS-IS and no
// guarantees are made as to its utility, functionality or correctness. It is
// provided solely as a guide to aid aspiring OS/2 2.x Presentation Manager
// programmers in developing their own PM applications. No modifications are
// to be made to this code for re-release as a same or different product. This
// code must be distributed (in its original entirety) with the executable
// portion of this product.
//
// -- Please register this shareware product for $10 today --
// See documentation for details
//
// Project Start Date: December 26, 1993
// Project Completion Date: January 3, 1994
//
// Written using Borland C++ for OS/2, version 1.0, Borland Resource Workshop,
// and the IBM OS/2 2.1 bitmap/icon editor
//
// File Last Modified: February 12, 1994
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// set compile-time flags for what os/2 header information should be included
////////////////////////////////////////////////////////////////////////////////
#define INCL_PM
#define INCL_DOSSESMGR
#define INCL_DOSMISC
#define INCL_WINPOINTERS
#define INCL_WINSTDFILE
#define INCL_DOSPROCESS
////////////////////////////////////////////////////////////////////////////////
// include C, C++, OS/2, application and resource header files
////////////////////////////////////////////////////////////////////////////////
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <time.h>
#include "filebar.h"
////////////////////////////////////////////////////////////////////////////////
// MakeHourglassPointer - macro to make the mouse pointer the hourglass
////////////////////////////////////////////////////////////////////////////////
#define MakeHourglassPointer() { \
HPOINTER pointer; \
pointer = WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE);\
WinSetPointer( HWND_DESKTOP, pointer ); \
}
////////////////////////////////////////////////////////////////////////////////
// MakeArrowPointer - macro to make the mouse pointer the arrow
////////////////////////////////////////////////////////////////////////////////
#define MakeArrowPointer() { \
HPOINTER pointer; \
pointer = WinQuerySysPointer( HWND_DESKTOP, SPTR_ARROW, FALSE);\
WinSetPointer( HWND_DESKTOP, pointer ); \
}
////////////////////////////////////////////////////////////////////////////////
// writeString - writes a string out with quotes on either side
////////////////////////////////////////////////////////////////////////////////
#define writeString(stream, string) fprintf(stream, "\"%s\"\n", string)
////////////////////////////////////////////////////////////////////////////////
// define application constants
////////////////////////////////////////////////////////////////////////////////
#define TEMPSTRING 64
#define AT_TOP TRUE
#define AT_BOTTOM FALSE
#define TIMERID 1
#define MAXTASKS 30
#define MAXMENUS 7
#define MAXITEMS 24
#define MAXACTIONSTRINGLENGTH CCHMAXPATH
#define MAXITEMNAMELENGTH 24
#define MAXMENUNAMELENGTH 20
#define MAXARGSTRINGLENGTH 32
#define MAXDIRSTRINGLENGTH CCHMAXPATH
#define WINDOWED 1
#define FULLSCREEN 2
#define PM 4
#define DOS 8
#define OS2 16
#define WINOS2 32
#define STARTMIN 64
#define STARTMAX 128
#define WPSFOLDER 256
#define STARTASWPS 512
#define SCALED 128
#define TILED 64
#define OS2SHELL "CMD.EXE"
#define OPTIONFILE "FILEBAR.INI"
#define LAUNCHFILE "STARTPRG.CMD"
#define LAUNCHINPUTS "/C STARTPRG.CMD"
#define SEPARATOR "────────────────────────"
#define FILEBARMENUON "~FileBar"
#define FILEBARMENUOFF "\x04"
#define TASKMENUON "~Task List"
#define TASKMENUOFF "~Tasks"
#define STARTINPUT '['
#define ENDINPUT ']'
#define BITMAPNAME "\\FILEBAR.BMP\0"
#define NOCOLOR 1
////////////////////////////////////////////////////////////////////////////////
// define function prototypes
////////////////////////////////////////////////////////////////////////////////
VOID displayBackground( VOID );
VOID resizeMenu( VOID );
VOID readOptionFile( VOID );
VOID writeOptionFile( VOID );
VOID readString( FILE* stream, CHAR* buffer );
VOID restartTimer( VOID );
VOID displayTimeDate( VOID );
VOID SwapTwoMenus( SHORT menu1, SHORT menu2 );
VOID SwapTwoItems(SHORT Menu, SHORT item1, SHORT item2);
VOID updateItemList( HWND hWnd );
VOID updateEditItemData( HWND hWnd );
VOID updateEditItemData( HWND hWnd );
SHORT startApplication( SHORT menu, SHORT item );
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY GenericProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY TimeDateProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY EditMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY AddAMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY EditItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY EditItemDataProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY AddAnItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY menuHandler(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY EnterParamProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
MRESULT EXPENTRY backgroundProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2);
extern "C" {
#define INCL_REXXSAA
#include "rexxsaa.h"
RexxStart rexxStart;
}
////////////////////////////////////////////////////////////////////////////////
// define global variables
////////////////////////////////////////////////////////////////////////////////
HAB hab;
HMQ hmq;
PID TaskId[MAXTASKS];
PFNWP menuMessageHandler;
FILEDLG fileDlgInfo;
MENUITEM menuData[MAXMENUS];
LONG ScreenSizeX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) + 2;
LONG ScreenSizeY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
LONG MenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
ULONG timerNumber;
USHORT ProgType[MAXMENUS][MAXITEMS];
USHORT oldProgType;
USHORT timeOption = TIMEANDDATE;
USHORT MenuSelection;
HWND hwndClient;
HWND hwndFrame;
HWND hwndMenu;
HWND TaskHandle[MAXTASKS];
HWND popUpMenu;
BOOL UpdateMenu[MAXMENUS];
BOOL FileBarMenuOn = TRUE;
BOOL BarPosition = AT_TOP;
BOOL timeSync;
BOOL checkBeforeDelete = TRUE;
BOOL showBackground = FALSE;
BOOL isBackgroundDisplayed = FALSE;
CHAR MenuName[MAXMENUS][MAXMENUNAMELENGTH];
CHAR ItemName[MAXMENUS][MAXITEMS][MAXITEMNAMELENGTH];
CHAR parameterTitle[MAXITEMNAMELENGTH];
CHAR ActionToDo[MAXMENUS][MAXITEMS][MAXACTIONSTRINGLENGTH];
CHAR CmdLnArgs[MAXMENUS][MAXITEMS][MAXARGSTRINGLENGTH];
CHAR Directory[MAXMENUS][MAXITEMS][MAXACTIONSTRINGLENGTH];
CHAR variableText[MAXARGSTRINGLENGTH-2];
CHAR oldItemName[MAXITEMNAMELENGTH];
CHAR oldDirectory[MAXACTIONSTRINGLENGTH];
CHAR oldAction[MAXACTIONSTRINGLENGTH];
CHAR oldCmdLn[MAXARGSTRINGLENGTH];
CHAR tmpBuffer[80];
CHAR backgroundBitmap[MAXACTIONSTRINGLENGTH];
PCHAR ParameterTextPtr;
BYTE backgroundAttr = 3 + TILED;
BYTE NumMenus;
BYTE NumItems[MAXMENUS];
USHORT ItemSelection;
USHORT taskItemSelected;
////////////////////////////////////////////////////////////////////////////////
// main function - application entry point
////////////////////////////////////////////////////////////////////////////////
main( int argc, char* argv[] )
{
hab = WinInitialize(0); // handle: anchor block
hmq = WinCreateMsgQueue(hab, 0); // handle: message queue
CHAR ClassName[] = "FileBar"; // store a name for our class
MENUITEM menuItem; // used to modify menu data
//--------------------------------------------------------------------------
// register the window class
//--------------------------------------------------------------------------
WinRegisterClass(hab,
ClassName, // name of class being registered
ClientWndProc, // window procedure for class
0, // class style
0); // extra memory to reserve
//--------------------------------------------------------------------------
// create a window with a menu bar added on. Note that the menu bar could
// be defined in the WinCreateStdWindow call (set the resource id equal= to
// MENUBAR) but is not since I need a handle to the menu (so I can later
// modify the menu). Thus, WinLoadMenu is used following WinCreateStdWindow
//--------------------------------------------------------------------------
ULONG FrameFlags = FCF_AUTOICON|FCF_TASKLIST|FCF_BORDER;
hwndFrame = WinCreateStdWindow(HWND_DESKTOP, // parent
WS_VISIBLE, // style
&FrameFlags, // control data
ClassName, // client name
"FileBar", // title bar text
0, // client style
0, // resource handle
0, // resource id
&hwndClient); // client pointer
hwndMenu = WinLoadMenu( hwndFrame, (HMODULE)0, MENUBAR );
//--------------------------------------------------------------------------
// move and size application to span entire top of desktop
//--------------------------------------------------------------------------
MakeHourglassPointer (); // switch to hourglass cursor
// during initialization
WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight),
ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
//--------------------------------------------------------------------------
// perform basic initialization
//--------------------------------------------------------------------------
NumMenus = 0;
MenuSelection = 100;
for ( short i = 0; i < MAXMENUS; i++ )
for (short j = 0; j < MAXITEMS; j++)
ActionToDo[i][j][1] = '\0';
for ( short k = 0; k < MAXMENUS; k++ ) {
WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT(100*(k+1),TRUE),MPFROMP(&menuData[k]));
menuItem = menuData[k];
menuItem.afStyle = MIS_STATIC;
menuItem.afAttribute = MIA_DISABLED;
menuItem.hwndSubMenu = (HWND)0;
WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*(k+1),TRUE),MPFROMP(&menuItem));
WinSetMenuItemText( hwndMenu, 100*(k+1), "");
UpdateMenu[ k ] = FALSE;
NumItems[ k ] = 0;
}
memset( &fileDlgInfo, 0, sizeof(FILEDLG));
fileDlgInfo.cbSize = sizeof(fileDlgInfo);
menuMessageHandler = WinSubclassWindow( hwndMenu, menuHandler );
//--------------------------------------------------------------------------
// change to directory that application executable is started from
//--------------------------------------------------------------------------
if (argc > 0) {
char temp[CCHMAXPATH];
short i;
strcpy(temp, argv[0]);
if (temp[1]==':')
DosSetDefaultDisk( (ULONG)(toupper(temp[0])-'A' + 1) );
i = strlen(temp);
while ((temp[i]!='\\') && (i>0))
i--;
if (i) {
temp[i]='\0';
if (DosSetCurrentDir( temp )!=0) {
char mesg[]="Could not switch to the directory holding the application";
WinMessageBox( HWND_DESKTOP, hwndFrame, mesg, temp, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
}
strcpy( backgroundBitmap, temp );
strcat( backgroundBitmap, BITMAPNAME );
}
//--------------------------------------------------------------------------
// read in the user option file and set up the menu bar appropriately
// check the user time/date option and put it on the menu bar
// reset our timer in case they want the current time displayed
//--------------------------------------------------------------------------
readOptionFile(); // read in option file
displayTimeDate(); // put time/date in menubar
restartTimer(); // resync our clock
displayBackground(); // restore user background bitmap
MakeArrowPointer (); // switch back to arrow pointer,
// we're done with initialization
WinSetParent( hwndFrame, HWND_DESKTOP, FALSE );
WinSetFocus( HWND_DESKTOP, hwndFrame );
//--------------------------------------------------------------------------
// create a message queue and then as long as there are messages to get,
// get them and dispatch them to our message handlers
//--------------------------------------------------------------------------
{
QMSG qmsg; // create a message queue
while( WinGetMsg( hab, &qmsg, (HWND)0, 0, 0 ) !=FALSE )
WinDispatchMsg( hab, &qmsg );
}
//--------------------------------------------------------------------------
// our application is done. Destroy timer, the window and the message queue
// call the system to destroy our anchor block and do final clean up work
//--------------------------------------------------------------------------
if (timerNumber != 0)
WinStopTimer( hab, hwndClient, timerNumber );
WinDestroyWindow(hwndFrame);
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
// a new font has been selected for our menu, resize and redraw the menubar
////////////////////////////////////////////////////////////////////////////////
VOID resizeMenu()
{
HPS hps;
FONTMETRICS fm;
hps = WinGetPS( hwndMenu );
GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &fm);
MenuHeight = fm.lLowerCaseDescent + fm.lMaxAscender + 4;
if (MenuHeight < (fm.lLowerCaseDescent + fm.lLowerCaseAscent + 2))
MenuHeight = fm.lLowerCaseDescent + fm.lLowerCaseAscent + 2;
if (MenuHeight < (WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2))
MenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
WinReleasePS( hps );
if (BarPosition==AT_BOTTOM)
WinSetWindowPos( hwndFrame, (HWND)0, 0, 0,
ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
else
WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight),
ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
}
////////////////////////////////////////////////////////////////////////////////
// subclassed menu handler for main application window
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY menuHandler(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch (msg) {
// if a menu has been highlighted, save which one it is so that we know
// which task to affect if something is chosen off cascading menu
case WM_MENUSELECT:
{
if ((SHORT1FROMMP(mp1)>TASKLIST_MENU) && (SHORT1FROMMP(mp1)<99)) {
taskItemSelected = SHORT1FROMMP(mp1);
}
return menuMessageHandler(hwnd, msg, mp1, mp2);
}
// resize menubar if a font was just dropped on us
case WM_PRESPARAMCHANGED:
{
if ( (ULONG)mp1 == PP_FONTNAMESIZE)
resizeMenu();
return menuMessageHandler(hwnd, msg, mp1, mp2);
}
default:
return menuMessageHandler(hwnd, msg, mp1, mp2);
}
}
////////////////////////////////////////////////////////////////////////////////
// This is the message processing facility for the main application thread
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch (msg) {
//----------------------------------------------------------------------
// if the application is terminating, write user settings to a file
//----------------------------------------------------------------------
case WM_CLOSE:
case WM_SAVEAPPLICATION:
case WM_QUIT: {
writeOptionFile();
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
//----------------------------------------------------------------------
// the application has been designed such that a WM_TIMER is sent by the
// system every minute (so that we can update our time on the menubar
// if necessary)
//----------------------------------------------------------------------
case WM_TIMER: {
if (!timeSync) {
WinStopTimer( hab, hwndClient, timerNumber );
timerNumber = WinStartTimer( hab, hwndClient, TIMERID, 60000);
timeSync = TRUE;
}
displayTimeDate();
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
//----------------------------------------------------------------------
// a WM_INITMENU message is sent just prior to any pulldown menu being
// displayed. This gives us a chance to change its contents before it
// is displayed.
//----------------------------------------------------------------------
case WM_INITMENU: {
SHORT menuId = SHORT1FROMMP(mp1);
//------------------------------------------------------------------
// if the FileBar menu is being readied for display, make sure the
// move-bar top/bottom item reads appropriately!
//------------------------------------------------------------------
if (menuId == FILEBAR_MENU) {
if (BarPosition == AT_TOP )
WinSetMenuItemText( HWNDFROMMP( mp2 ), FILEBAR_MOVEBAR,
"~Move to Bottom");
else
WinSetMenuItemText( HWNDFROMMP( mp2 ), FILEBAR_MOVEBAR,
"~Move to Top");
WinCheckMenuItem( hwndMenu, FILEBAR_DISPLAYBACKGROUND, showBackground);
WinCheckMenuItem( hwndMenu, FILEBAR_FILEBARMENU, (TRUE - FileBarMenuOn));
WinCheckMenuItem( hwndMenu, FILEBAR_CONFIRMCLOSE, checkBeforeDelete);
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
//------------------------------------------------------------------
// if the user is pulling down the task list, put a current copy of
// the task list in the menu and store copies of all the tasks id
// numbers and handles just in case they want to jump to one of them
//------------------------------------------------------------------
if (menuId == TASKLIST_MENU) {
PCHAR text;
MENUITEM menuItem;
BYTE index;
ULONG numItems;
ULONG Buffer;
PSWBLOCK SwitchBlockPtr;
// clear out the menu, get it ready for new task entries
// for (short i = menuId+1; i < menuId+MAXITEMS+1; i++ )
for (short i = menuId+1; i < menuId+MAXITEMS+1; i++ )
WinSendMsg( HWNDFROMMP( mp2 ), MM_DELETEITEM,
MPFROM2SHORT( i, TRUE ), 0 );
// get the # of items and the switch list from the system
numItems = WinQuerySwitchList( hab, NULL, 0 );
Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
PVOID my = new BYTE[Buffer];
WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
// insert each task as an entry under the task list menu
SwitchBlockPtr = (PSWBLOCK)(my);
menuItem.iPosition = 0;
menuItem.afStyle = MIS_MULTMENU|MIS_SINGLE;
menuItem.afAttribute = 0;
menuItem.hItem = 0;
menuItem.id = TASKLIST_MENU;
WinSendMsg(menuItem.hwndSubMenu , MM_SETDEFAULTITEMID, MPFROMSHORT(TASK_SWITCHTO), NULL);
//for (short j = 1; j < numItems-1; j++ ) {
for (short j = 0; j < numItems; j++ ) {
menuItem.id++;
if ((SwitchBlockPtr->aswentry[j].swctl.uchVisibility != SWL_GRAYED) &&
(strcmp(SwitchBlockPtr->aswentry[j].swctl.szSwtitle,"Workplace Shell")) &&
(SwitchBlockPtr->aswentry[j].swctl.uchVisibility != SWL_INVISIBLE) &&
(SwitchBlockPtr->aswentry[j].swctl.hwnd != hwndFrame)) {
menuItem.hwndSubMenu = WinLoadMenu(hwndMenu, 0, TASKMENUCLOSE);
// remove ctrl characters from task list
index = 0;
text = SwitchBlockPtr->aswentry[j].swctl.szSwtitle;
while (text[++index]!='\0')
if (text[index]<' ')
text[index]=' ';
WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
(MENUITEM*)&menuItem,
&(SwitchBlockPtr->aswentry[j].swctl.szSwtitle) );
TaskId[j] = SwitchBlockPtr->aswentry[j].swctl.idProcess;
TaskHandle[j] = SwitchBlockPtr->aswentry[j].swctl.hwnd;
WinSendMsg(menuItem.hwndSubMenu, MM_SETDEFAULTITEMID, MPFROMSHORT(TASK_SWITCHTO), NULL);
WinSetWindowBits(menuItem.hwndSubMenu , QWL_STYLE, MS_CONDITIONALCASCADE, MS_CONDITIONALCASCADE);
}
}
delete( my );
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
//------------------------------------------------------------------
// one of the user menus is being initialized; if it has been marked
// as needing to be updated, fill the menu with the current items
// the user has set up
//------------------------------------------------------------------
if (menuId >= 100) {
int MenuToUpdate = menuId / 100 - 1;
if ( UpdateMenu[ MenuToUpdate ] ) {
UpdateMenu[ MenuToUpdate ] = FALSE;
{
MENUITEM menuItem;
for (short i = menuId+1; i < menuId+MAXITEMS+1; i++ )
WinSendMsg( HWNDFROMMP( mp2 ), MM_DELETEITEM,
MPFROM2SHORT( i, TRUE ), 0 );
menuItem.iPosition = MIT_END;
menuItem.afStyle = MIS_TEXT;
menuItem.afAttribute = 0;
menuItem.hItem = 0;
menuItem.hwndSubMenu = (HWND)0;
menuItem.id = menuId;
for (short j = 0; j < NumItems[ MenuToUpdate ]; j++ ) {
menuItem.id++;
if (ItemName[MenuToUpdate][j][0] != '\0')
WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
(MENUITEM*)&menuItem,
ItemName[MenuToUpdate][j] );
else {
menuItem.afStyle = MIS_SEPARATOR;
WinSendMsg( HWNDFROMMP(mp2), MM_INSERTITEM,
(MENUITEM*)&menuItem,
ItemName[MenuToUpdate][j] );
menuItem.afStyle = MIS_TEXT;
}
}
}
}
return WinDefWindowProc(hwnd, msg, mp1, mp2);
}
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
case WM_COMMAND: {
USHORT command = SHORT1FROMMP(mp1);
//------------------------------------------------------------------
// expand or shrink FileBar system menus
//------------------------------------------------------------------
if ( command == FILEBAR_FILEBARMENU) {
CHAR menuOn[] = FILEBARMENUON;
CHAR menuOff[] = FILEBARMENUOFF;
CHAR taskOn[] = TASKMENUON;
CHAR taskOff[] = TASKMENUOFF;
FileBarMenuOn = TRUE - FileBarMenuOn;
if (FileBarMenuOn) {
WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOn);
WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOn);
}
else {
WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOff);
WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOff);
}
return 0;
}
//------------------------------------------------------------------
// show the display background dialog box
//------------------------------------------------------------------
if ( command == FILEBAR_DISPLAYBACKGROUND) {
WinDlgBox(HWND_DESKTOP,
hwnd,
(PFNWP)backgroundProc,
0,
BACKGROUNDWIN,
(PVOID)NULL);
displayBackground();
return 0;
}
//------------------------------------------------------------------
// close the chosen task
//------------------------------------------------------------------
if ( command == FILEBAR_CONFIRMCLOSE) {
checkBeforeDelete = TRUE - checkBeforeDelete;
return 0;
}
//------------------------------------------------------------------
// close the chosen task
//------------------------------------------------------------------
if ( command == TASK_CLOSE) {
ULONG numItems;
ULONG Buffer;
PSWBLOCK SwitchBlockPtr;
PID killedTaskId;
HWND killedTaskHandle;
if (checkBeforeDelete) {
CHAR title[] = "FileBar - Close Task";
CHAR text[] = "Closing may result in the destruction of unsaved data. Are you sure you want to close this task?";
if (WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
MB_MOVEABLE|MB_ICONQUESTION|MB_YESNO) == MBID_NO)
return 0;
}
killedTaskId = TaskId[taskItemSelected - TASKLIST_MENU - 1];
killedTaskHandle = TaskHandle[taskItemSelected - TASKLIST_MENU - 1];
WinSendMsg( killedTaskHandle, WM_CLOSE, 0, 0 );
// get the # of items and the switch list from the system
numItems = WinQuerySwitchList( hab, NULL, 0 );
Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
PVOID my = new BYTE[Buffer];
WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
SwitchBlockPtr = (PSWBLOCK)(my);
// if task did not close willingly, kill its process!
for (short j = 0; j < numItems; j++ )
if (SwitchBlockPtr->aswentry[j].swctl.hwnd == killedTaskHandle)
DosKillProcess( DKP_PROCESS, killedTaskId );
delete( my );
return 0;
}
//------------------------------------------------------------------
// show the chosen task
//------------------------------------------------------------------
if ( command == TASK_SHOW) {
WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
(HWND)0, 0, 0, 0, 0, SWP_SHOW);
return 0;
}
//------------------------------------------------------------------
// hide the chosen task
//------------------------------------------------------------------
if ( command == TASK_HIDE) {
WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
(HWND)0, 0, 0, 0, 0, SWP_HIDE);
return 0;
}
//------------------------------------------------------------------
// maximize the chosen task
//------------------------------------------------------------------
if ( command == TASK_MAX) {
HSWITCH switchHandle = WinQuerySwitchHandle( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
TaskId[taskItemSelected - TASKLIST_MENU- 1]);
WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU- 1], TRUE );
WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
(HWND)0, 0, 0, 0, 0, SWP_MAXIMIZE);
WinSwitchToProgram( switchHandle );
return 0;
}
//------------------------------------------------------------------
// minimize the chosen task
//------------------------------------------------------------------
if ( command == TASK_MIN) {
WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU- 1], TRUE );
WinSetWindowPos( TaskHandle[taskItemSelected - TASKLIST_MENU- 1],
(HWND)0, 0, 0, 0, 0, SWP_MINIMIZE);
return 0;
}
//------------------------------------------------------------------
// the user has selected something from the tasklist menu, switch
// control to that task, if possible
//------------------------------------------------------------------
if ( command == TASK_SWITCHTO) {
HSWITCH switchHandle;
switchHandle = WinQuerySwitchHandle( TaskHandle[taskItemSelected - TASKLIST_MENU-1],
TaskId[taskItemSelected - TASKLIST_MENU-1]);
if (switchHandle == 0) {
CHAR title[] = "FileBar Task Switch Error";
CHAR text[] = "ERROR! Could not locate task! The task may have already terminated.";
WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
return 0;
}
if (WinSwitchToProgram( switchHandle ) != 0) {
CHAR title[] = "FileBar Task Switch Error";
CHAR text[] = "ERROR! Could not switch to task!";
WinMessageBox( HWND_DESKTOP, hwnd, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
WinShowWindow( TaskHandle[taskItemSelected - TASKLIST_MENU], TRUE );
return 0;
}
//------------------------------------------------------------------
// user wants to shutdown system
//------------------------------------------------------------------
if ( command == 99 ) {
char title[] = "FileBar - Shutdown System";
char text[] = "Are you sure that you want to close all windows and active programs and shutdown your system? Select OK to continue shutdown. Select Cancel to end this task.";
if (WinMessageBox( HWND_DESKTOP, hwndFrame, text, title, 0,
MB_DEFBUTTON2|MB_MOVEABLE|MB_ICONEXCLAMATION|MB_OKCANCEL) == MBID_CANCEL)
return 0;
writeOptionFile();
WinSetWindowPos( hwndFrame, (HWND)0, 0, 0, 0, 0, SWP_HIDE);
//WinBroadcastMsg( HWND_DESKTOP, WM_QUIT, 0, 0 );
WinPostMsg( hwndClient, WM_QUIT, 0, 0 );
WinShutdownSystem( WinQueryAnchorBlock( HWND_DESKTOP ), hmq );
}
//------------------------------------------------------------------
// the user has selected an option off the user menus. Activate the
// item they have selected
//------------------------------------------------------------------
if (( command > 99 ) && (command % 100)) {
INT MenuToUpdate = command / 100 - 1;
INT ItemToUpdate = command % 100 - 1;
if ((ItemToUpdate>=MAXITEMS) || (MenuToUpdate>=MAXMENUS))
return 0;
if ((MenuToUpdate >= 0) && (MenuToUpdate<MAXMENUS))
//errorCode = startApplication( MenuToUpdate, ItemToUpdate );
startApplication( MenuToUpdate, ItemToUpdate );
/*
if (errorCode != 0) {
CHAR title[34];
char message[500];
ULONG MessageLength;
memset( &message, 0, sizeof(message));
DosGetMessage(NULL,0,message,sizeof(message),errorCode,"OSO001.MSG",&MessageLength);
sprintf(title, "FileBar (Menu %d, Item %d) - Application Launch Error", MenuToUpdate, ItemToUpdate);
WinMessageBox( HWND_DESKTOP, hwnd, message, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
*/
return 0;
}
//------------------------------------------------------------------
// it was not a tasklist or user item, process now as usual
//------------------------------------------------------------------
switch( command ) {
//--------------------------------------------------------------
// the user wants to save current options
//--------------------------------------------------------------
case FILEBAR_SAVEOPTIONS: {
char title[] = "FileBar - Save Menu Configuration";
char message[] = "The current user menu configuration has been successfully saved!";
writeOptionFile();
WinMessageBox( HWND_DESKTOP, hwnd, message, title, 0,
MB_MOVEABLE|MB_INFORMATION|MB_OK);
return 0;
}
//--------------------------------------------------------------
// the user wants to edit the menu structure
//--------------------------------------------------------------
case FILEBAR_EDITMENU: {
return (VOID*)WinDlgBox(HWND_DESKTOP,
hwnd,
(PFNWP)EditMenuProc,
0,
EDITMENU,
(PVOID)NULL);
}
//--------------------------------------------------------------
// the user wants to select their time/date display options
//--------------------------------------------------------------
case FILEBAR_TIMEOPTION: {
return (VOID*)WinDlgBox(HWND_DESKTOP,
hwnd,
(PFNWP)TimeDateProc,
0,
TIMEOPTIONS,
(PVOID)NULL);
}
//--------------------------------------------------------------
// the user wants to get general help on filebar
//--------------------------------------------------------------
case FILEBAR_GENHELP: {
return (VOID*)WinDlgBox(HWND_DESKTOP,
hwnd,
(PFNWP)GenericProc,
0,
GENERAL_HELP,
(PVOID)NULL);
}
//--------------------------------------------------------------
// the user wants to see product information for filebar
//--------------------------------------------------------------
case FILEBAR_PRODINFO: {
return (VOID*)WinDlgBox(HWND_DESKTOP,
hwnd,
(PFNWP)GenericProc,
0,
PRODUCT_INFO,
(PVOID)NULL);
}
//--------------------------------------------------------------
// the user wishes to move the filebar from its current position
// to either to the top or bottom of the desktop
//--------------------------------------------------------------
case FILEBAR_MOVEBAR: {
if (BarPosition==AT_TOP) {
BarPosition = AT_BOTTOM;
WinSetWindowPos( hwndFrame, (HWND)0, 0, 0,
ScreenSizeX, MenuHeight, SWP_MOVE);
}
else {
BarPosition = AT_TOP;
WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight),
ScreenSizeX, MenuHeight, SWP_MOVE);
}
return 0;
}
//--------------------------------------------------------------
// the user wishes to exit the filebar application
//--------------------------------------------------------------
case FILEBAR_EXIT: {
return (VOID*)WinPostMsg( hwnd, WM_QUIT, 0, 0);
}
//--------------------------------------------------------------
// something besides our menus sent a message, pass the message
// to the system for default processing
//--------------------------------------------------------------
default:
return WinDefWindowProc(hwnd, msg, mp1, mp2); // default processing
}
}
//----------------------------------------------------------------------
// we were sent a message that we don't care about, pass it onto system
// for default processing
//----------------------------------------------------------------------
default:
return WinDefWindowProc(hwnd, msg, mp1, mp2); // default processing
};
}
////////////////////////////////////////////////////////////////////////////////
// readOptionFile - will read the option file (generated by the app) from disk,
// if it exists and will restore the application to the state in which it was
// last left
////////////////////////////////////////////////////////////////////////////////
void readOptionFile( void )
{
int currentMenu = 100;
FILE *optionFile;
//--------------------------------------------------------------------------
// if the option file exists on disk, read it in and restore old menu,
// otherwise we will return and rely on default values
//--------------------------------------------------------------------------
if ((optionFile = fopen(OPTIONFILE,"rt")) != NULL) {
RGB2 rgb = {0,0,0,0};
ULONG color;
CHAR temp[200];
ScreenSizeX = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN) + 2;
ScreenSizeY = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
MenuHeight = WinQuerySysValue(HWND_DESKTOP, SV_CYMENU) + 2;
fscanf(optionFile, "%d %d", &timeOption, &BarPosition);
// restore user's desired bar position
if (BarPosition==AT_BOTTOM) {
WinSetWindowPos( hwndFrame, (HWND)0, 0, 0,
ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
}
else {
WinSetWindowPos( hwndFrame, (HWND)0, 0, (ScreenSizeY-MenuHeight),
ScreenSizeX, MenuHeight, SWP_MOVE|SWP_SIZE);
}
// restore user's menus and menu choices
fscanf(optionFile, "%d", &NumMenus);
for (short i = 0; i < NumMenus; i++ ) {
UpdateMenu[i] = TRUE;
readString( optionFile, (CHAR*)&MenuName[i] );
WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*i+100,TRUE),MPFROMP(&menuData[i]));
WinSetMenuItemText( hwndMenu, 100*i+100, &MenuName[i]);
fscanf(optionFile, "%d", &NumItems[i]);
for (short j = 0; j < NumItems[i]; j++) {
readString( optionFile, (CHAR*)&ItemName[i][j] );
readString( optionFile, (CHAR*)&ActionToDo[i][j] );
readString( optionFile, (CHAR*)&CmdLnArgs[i][j] );
readString( optionFile, (CHAR*)&Directory[i][j] );
fscanf( optionFile, "%d", &ProgType[i][j] );
}
currentMenu = currentMenu + 100;
}
readString( optionFile, (CHAR*)&temp );
if (temp[0]!='\0') {
WinSetPresParam( hwndMenu, PP_FONTNAMESIZE, sizeof(temp), &temp );
resizeMenu();
}
fscanf( optionFile, "%d", &checkBeforeDelete );
if (fscanf( optionFile, "%d", &FileBarMenuOn )!=EOF) {
CHAR menuOn[] = FILEBARMENUON;
CHAR menuOff[] = FILEBARMENUOFF;
CHAR taskOn[] = TASKMENUON;
CHAR taskOff[] = TASKMENUOFF;
if (FileBarMenuOn) {
WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOn);
WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOn);
}
else {
WinSetMenuItemText( hwndMenu, FILEBAR_MENU, menuOff);
WinSetMenuItemText( hwndMenu, TASKLIST_MENU, taskOff);
}
}
if (fscanf( optionFile, "%d", &showBackground )!=EOF) {
fscanf( optionFile, "%d", &backgroundAttr );
readString( optionFile, (CHAR*)&backgroundBitmap );
}
for (i=PP_FOREGROUNDCOLOR; i<=PP_BORDERCOLOR; i=i+2)
if (fscanf(optionFile, "%ld", &color )!=EOF)
if ( color != NOCOLOR) {
rgb.bRed = (BYTE)(color/65536);
color = color%65536;
rgb.bGreen = (BYTE)(color/256);
color = color%256;
rgb.bBlue = (BYTE)(color);
WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
}
for (i=PP_ACTIVECOLOR; i<=PP_INACTIVETEXTBGNDCOLOR; i=i+2)
if (fscanf(optionFile, "%ld", &color )!=EOF)
if ( color != NOCOLOR) {
rgb.bRed = (BYTE)(color/65536);
color = color%65536;
rgb.bGreen = (BYTE)(color/256);
color = color%256;
rgb.bBlue = (BYTE)(color);
WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
}
if (fscanf(optionFile, "%ld", &color )!=EOF)
if ( color != NOCOLOR) {
rgb.bRed = (BYTE)(color/65536);
color = color%65536;
rgb.bGreen = (BYTE)(color/256);
color = color%256;
rgb.bBlue = (BYTE)(color);
WinSetPresParam( hwndMenu, PP_SHADOW, sizeof(rgb), &rgb);
}
for (i=PP_MENUFOREGROUNDCOLOR; i<=PP_MENUDISABLEDBGNDCOLOR; i=i+2)
if (fscanf(optionFile, "%ld", &color )!=EOF)
if ( color != NOCOLOR) {
rgb.bRed = (BYTE)(color/65536);
color = color%65536;
rgb.bGreen = (BYTE)(color/256);
color = color%256;
rgb.bBlue = (BYTE)(color);
WinSetPresParam( hwndMenu, i, sizeof(rgb), &rgb);
}
fclose( optionFile );
}
}
////////////////////////////////////////////////////////////////////////////////
// writeOptionFile - will write the application state to the option file
////////////////////////////////////////////////////////////////////////////////
void writeOptionFile( void )
{
SHORT currentMenu = 100;
FILE *optionFile;
//--------------------------------------------------------------------------
// if the option file exists on disk, read it in and restore old menu,
// otherwise we will return and rely on default values
//--------------------------------------------------------------------------
if ((optionFile = fopen(OPTIONFILE, "wt")) == NULL) {
// if not able to save, alert the user
CHAR title[] = "FileBar Error";
CHAR text[] = "Error writing application configuration file! Application data was NOT saved!";
WinMessageBox( HWND_DESKTOP, hwndClient, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
else {
char mesg[TEMPSTRING];
ULONG length;
RGB2 rgb;
// save user's desired bar position
fprintf(optionFile, "%d %d\n", timeOption, BarPosition);
// save user's menus and menu choices
fprintf(optionFile, "%d\n", NumMenus);
for (short i = 0; i < NumMenus; i++ ) {
writeString( optionFile, (CHAR*)&MenuName[i] );
fprintf(optionFile, "%d\n", NumItems[i]);
for (short j = 0; j < NumItems[i]; j++) {
writeString( optionFile, (CHAR*)&ItemName[i][j] );
writeString( optionFile, (CHAR*)&ActionToDo[i][j] );
writeString( optionFile, (CHAR*)&CmdLnArgs[i][j] );
writeString( optionFile, (CHAR*)&Directory[i][j] );
fprintf( optionFile, "%d\n", ProgType[i][j] );
}
currentMenu = currentMenu + 100;
}
if (WinQueryPresParam( hwndMenu, PP_FONTNAMESIZE, 0, &length, sizeof(mesg), &mesg, 0)!=FALSE)
writeString( optionFile, (CHAR*)&mesg );
else
fprintf( optionFile, "\"\"\n" );
fprintf( optionFile, "%d\n%d\n%d\n%d\n", checkBeforeDelete, FileBarMenuOn, showBackground, backgroundAttr );
writeString( optionFile, (CHAR*)&backgroundBitmap );
// save menu scheme of colors
for (i=PP_FOREGROUNDCOLOR; i<=PP_BORDERCOLOR; i=i+2) {
if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0) != 0)
fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
else fprintf(optionFile, "%ld\n", NOCOLOR );
}
for (i=PP_ACTIVECOLOR; i<=PP_INACTIVETEXTBGNDCOLOR; i=i+2) {
if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0) != 0)
fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
else fprintf(optionFile, "%ld\n", NOCOLOR );
}
if (WinQueryPresParam( hwndMenu, PP_SHADOW, 0, 0, sizeof(rgb), &rgb, 0) != 0)
fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
else fprintf(optionFile, "%ld\n", NOCOLOR );
for (i=PP_MENUFOREGROUNDCOLOR; i<=PP_MENUDISABLEDBGNDCOLOR; i=i+2) {
if (WinQueryPresParam( hwndMenu, i, 0, 0, sizeof(rgb), &rgb, 0) != 0)
fprintf(optionFile, "%ld\n", (ULONG)(rgb.bRed*65536+rgb.bGreen*256+rgb.bBlue) );
else fprintf(optionFile, "%ld\n", NOCOLOR );
}
fclose( optionFile );
}
}
////////////////////////////////////////////////////////////////////////////////
// readString will read a sequence of characters that is bounded on both sides
// by quote (") characters (We can't use fscanf because it won't read spaces)
////////////////////////////////////////////////////////////////////////////////
VOID readString( FILE* stream, CHAR* buffer )
{
do { // search for first " character
if (fscanf( stream, "%c", buffer)==EOF) break;
} while ( (*buffer) !='"');
buffer--;
do { // keep putting characters into the buffer
buffer++; // " character
if (fscanf( stream, "%c", buffer)==EOF) break;
//fscanf( stream, "%c", buffer); // until we hit the 2nd and terminating
} while ( (*buffer) !='"');
*buffer = '\0'; // store a NULL to terminate the string
}
////////////////////////////////////////////////////////////////////////////////
// Message handler for a generic information-only dialog box (help & prod info)
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY GenericProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// if we receive any system message, dismiss the dialog box
//----------------------------------------------------------------------
case WM_COMMAND:
{
WinDismissDlg( hWnd, TRUE );
return 0;
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// starts or restarts a timer to signal our program when the next minute occurs
////////////////////////////////////////////////////////////////////////////////
VOID restartTimer( VOID )
{
if ((timeOption == TIMEONLY) || (timeOption==TIMEANDDATE) ||
(timeOption == OTHERTIMEONLY) || (timeOption==OTHERTIMEANDDATE)) {
// only do this if the user needs to see the current time
struct tm *time_now;
time_t currentTime;
tzset();
time(¤tTime);
time_now = localtime( ¤tTime );
timeSync = FALSE;
timerNumber = WinStartTimer( hab, hwndClient, TIMERID, (60-(time_now->tm_sec))*1000);
}
}
////////////////////////////////////////////////////////////////////////////////
// displayTimeDate is used to place current date and/or time on the FileBar
////////////////////////////////////////////////////////////////////////////////
VOID displayTimeDate( VOID )
{
char tmp1[32];
char tmp2[32];
CHAR buffer[50] = { '\0' };
struct tm *time_now;
time_t currentTime;
tzset();
time(¤tTime);
time_now = localtime( ¤tTime );
if ((timeOption == TIMEONLY) || (timeOption == TIMEANDDATE)) {
strftime( tmp1, sizeof(tmp1), "%I", time_now);
strftime( tmp2, sizeof(tmp2), ":%M %p ", time_now);
if (tmp1[0] == '0')
tmp1[0]=' ';
strcat( buffer, tmp1 );
strcat( buffer, tmp2 );
}
if (timeOption == TIMEANDDATE)
strcat( buffer, " " );
if ((timeOption == DATEONLY) || (timeOption == TIMEANDDATE)) {
strftime( tmp1, sizeof(tmp1), "%B", time_now);
strftime( tmp2, sizeof(tmp2), "%d, %Y ", time_now);
if (tmp2[0] == '0') {
tmp2[0] = ' ';
strcat( buffer, tmp1 );
strcat( buffer, tmp2 );
}
else {
strcat( buffer, tmp1 );
strcat( buffer, " \0" );
strcat( buffer, tmp2 );
}
}
else if (timeOption == OTHERTIMEONLY)
strftime( buffer, sizeof(buffer), "%H:%M ", time_now);
else if (timeOption == OTHERDATEONLY)
strftime( buffer, sizeof(buffer), "%d %B %Y ", time_now);
else if (timeOption == OTHERTIMEANDDATE) {
strftime( tmp1, sizeof(tmp1), "%H:%M ", time_now );
strftime( tmp2, sizeof(tmp2), "%d %B %Y ", time_now );
if (tmp1[0] == '0')
tmp1[0] = ' ';
if (tmp2[0] == '0')
tmp2[0] = ' ';
else
strcat( tmp1, " " );
strcat( buffer, tmp1 );
strcat( buffer, tmp2 );
}
if (buffer[0]=='0')
buffer[0]=' ';
WinSetMenuItemText( hwndMenu, TIMEDATE, &buffer );
}
////////////////////////////////////////////////////////////////////////////////
// Message handler for time and date option setting dialog
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY TimeDateProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop and check
// the appropriate radio button for whatever setting they currently have
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
WinSendDlgItemMsg( hWnd, timeOption, BM_SETCHECK,
MPFROM2SHORT( 1, 0 ), 0);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// we received a change in control, update menubar time
//----------------------------------------------------------------------
case WM_CONTROL:
{
timeOption = NONE;
if (WinQueryButtonCheckstate( hWnd, TIMEONLY ))
timeOption = TIMEONLY;
else if (WinQueryButtonCheckstate( hWnd, DATEONLY ))
timeOption = DATEONLY;
else if (WinQueryButtonCheckstate( hWnd, TIMEANDDATE ))
timeOption = TIMEANDDATE;
else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEONLY ))
timeOption = OTHERTIMEONLY;
else if (WinQueryButtonCheckstate( hWnd, OTHERDATEONLY ))
timeOption = OTHERDATEONLY;
else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEANDDATE ))
timeOption = OTHERTIMEANDDATE;
WinStopTimer( hab, hwndClient, timerNumber );
restartTimer();
displayTimeDate();
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// if we receive any system message, dismiss dialog and store new option
//----------------------------------------------------------------------
case WM_COMMAND:
{
timeOption = NONE;
if (WinQueryButtonCheckstate( hWnd, TIMEONLY ))
timeOption = TIMEONLY;
else if (WinQueryButtonCheckstate( hWnd, DATEONLY ))
timeOption = DATEONLY;
else if (WinQueryButtonCheckstate( hWnd, TIMEANDDATE ))
timeOption = TIMEANDDATE;
else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEONLY ))
timeOption = OTHERTIMEONLY;
else if (WinQueryButtonCheckstate( hWnd, OTHERDATEONLY ))
timeOption = OTHERDATEONLY;
else if (WinQueryButtonCheckstate( hWnd, OTHERTIMEANDDATE ))
timeOption = OTHERTIMEANDDATE;
// stop current timer (if one exists) and start a new one
// display new time and date according to new option setting
WinStopTimer( hab, hwndClient, timerNumber );
restartTimer();
displayTimeDate();
WinDismissDlg( hWnd, TRUE );
return 0;
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// EditMenuProc - the message handler for editing a menu dialog box
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY EditMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// if double-clicked an entry, allow them to edit it
//----------------------------------------------------------------------
case WM_CONTROL:
{
if ((SHORT1FROMMP(mp1)==CURMENULIST) && (SHORT2FROMMP(mp1)==LN_ENTER))
return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( EDITMENUBUTTON, 0 ), mp2 );
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop and put
// the current data into appropriate list boxes
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
for (short i=0; i<NumMenus; i++)
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
MPFROM2SHORT( LIT_END, 0 ),
MenuName[i] );
if (NumMenus > 0) {
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( 0, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
}
else {
WinEnableControl( hWnd, EDITMENUBUTTON, FALSE );
WinEnableControl( hWnd, REMOVEMENU, FALSE );
WinEnableControl( hWnd, MOVEMENULEFT, FALSE );
WinEnableControl( hWnd, MOVEMENURIGHT, FALSE );
}
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// process a command message received from the system
//----------------------------------------------------------------------
case WM_COMMAND: {
USHORT command = SHORT1FROMMP(mp1);
switch( command )
{
//--------------------------------------------------------------
// if they pressed OK button, dismiss dialog and return
//--------------------------------------------------------------
case DID_OK: {
WinDismissDlg( hWnd, TRUE );
return 0;
}
//--------------------------------------------------------------
// they want to edit a menu
//--------------------------------------------------------------
case EDITMENUBUTTON: {
if (NumMenus == 0) {
WinAlarm(HWND_DESKTOP, WA_ERROR);
return 0;
}
// find out what menu they've selected in list box
MenuSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
// display edit menu dialog box
WinDlgBox(HWND_DESKTOP,
hWnd,
(PFNWP)EditItemProc,
0,
EDITITEM,
(PVOID)NULL);
// change the item in the list box and select it
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEALL, 0, 0 );
for (short i=0; i<NumMenus; i++)
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
MPFROM2SHORT( LIT_END, 0 ),
MenuName[i] );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( MenuSelection, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
return 0;
}
//--------------------------------------------------------------
// the user wants to add another menu to the menubar
//--------------------------------------------------------------
case ADDMENU: {
MenuSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
// error if no room for another menu
if (NumMenus >= MAXMENUS) {
char text[]="Error! Maximum number of user-menus already defined!";
char title[]="Add A Menu";
WinMessageBox( HWND_DESKTOP, hWnd, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
return 0;
}
WinDlgBox(HWND_DESKTOP,
hWnd,
(PFNWP)AddAMenuProc,
0,
ADDAMENU,
(PVOID)NULL);
// if first menu to be added, enable buttons
if (NumMenus > 0) {
WinEnableControl( hWnd, EDITMENUBUTTON, TRUE );
WinEnableControl( hWnd, REMOVEMENU, TRUE );
WinEnableControl( hWnd, MOVEMENULEFT, TRUE );
WinEnableControl( hWnd, MOVEMENURIGHT, TRUE );
}
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEALL, 0, 0 );
for (short i=0; i<NumMenus; i++)
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
MPFROM2SHORT( LIT_END, 0 ),
MenuName[i] );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( MenuSelection, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
return 0;
}
//--------------------------------------------------------------
// the user wants to remove a menu from the menu list box
//--------------------------------------------------------------
case REMOVEMENU: {
char text[]="If you remove this menu, there will be no way to recover it. Are you sure you want to remove this menu?";
char title[]="Remove Menu";
if (NumMenus == 0) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
if (NumMenus > 0)
if (WinMessageBox( HWND_DESKTOP, hWnd, text, title, 0,
MB_MOVEABLE|MB_WARNING|MB_YESNO|MB_DEFBUTTON2) == MBID_YES ) {
short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
CHAR noName[]="";
MENUITEM menuItem;
// delete it from the lisr box
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
MPFROM2SHORT( index, 0 ), 0 );
// delete it from menu structure
MakeHourglassPointer ();
WinSetMenuItemText( hwndMenu, 100*index+100, noName);
for (short i=index+1; i<MAXMENUS; i++) {
SwapTwoMenus( i-1, i );
}
NumItems[MAXMENUS-1] = 0;
MenuName[MAXMENUS-1][0] = '\0';
if (NumMenus > 0) {
int newIndex = index-1;
if (0 > newIndex)
newIndex = 0;
if (index == NumMenus-1)
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( newIndex, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
else
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( index, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
}
NumItems[NumMenus] = 0;
WinSendMsg( hwndMenu, MM_QUERYITEM, MPFROM2SHORT(NumMenus*100,TRUE),MPFROMP(&menuData[index]));
menuItem = menuData[index];
menuItem.afStyle = MIS_STATIC;
menuItem.afAttribute = MIA_DISABLED;
menuItem.hwndSubMenu = (HWND)0;
WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(NumMenus*100,TRUE),MPFROMP(&menuItem));
WinSetMenuItemText( hwndMenu, 100*MAXMENUS, noName);
NumItems[ NumMenus ] = 0;
UpdateMenu[ NumMenus ] = FALSE;
NumMenus--;
// if we deleted only menu, disable menu buttons
if (NumMenus == 0) {
WinEnableControl( hWnd, EDITMENUBUTTON, FALSE );
WinEnableControl( hWnd, REMOVEMENU, FALSE );
WinEnableControl( hWnd, MOVEMENULEFT, FALSE );
WinEnableControl( hWnd, MOVEMENURIGHT, FALSE );
}
MakeArrowPointer ();
}
return 0;
}
//--------------------------------------------------------------
// move menu left in menu structure
//--------------------------------------------------------------
case MOVEMENULEFT: {
short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
if ((NumMenus == 0) || (index == 0)) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
MakeHourglassPointer ();
SwapTwoMenus( index-1, index );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
MPFROM2SHORT( index, 0 ), 0 );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
MPFROM2SHORT( index-1, 0 ), MenuName[index-1] );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( index-1, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
MakeArrowPointer ();
return 0;
}
//--------------------------------------------------------------
// move menu right in menu structure
//--------------------------------------------------------------
case MOVEMENURIGHT: {
short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, CURMENULIST,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
if ((NumMenus == 0) || (index == (NumMenus)-1)) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
MakeHourglassPointer ();
SwapTwoMenus( index, index+1 );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_DELETEITEM,
MPFROM2SHORT( index, 0 ), 0 );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_INSERTITEM,
MPFROM2SHORT( index+1, 0 ), MenuName[index+1] );
WinSendDlgItemMsg( hWnd, CURMENULIST, LM_SELECTITEM,
MPFROM2SHORT( index+1, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
MakeArrowPointer ();
return 0;
}
//--------------------------------------------------------------
// nothing we care about, pass it onto the system default proc
//--------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// SwapTwoMenus will swap the FileBar stored information entries for two menus
// indicated by menu1 and menu2. The text on the displayed menubar will also
// be changed to indicate the swap.
////////////////////////////////////////////////////////////////////////////////
void SwapTwoMenus( short menu1, short menu2 )
{
SHORT t1;
for (short i=0; i<MAXITEMS; i++) {
strcpy( tmpBuffer, ItemName[menu1][i] );
strcpy( ItemName[menu1][i], ItemName[menu2][i] );
strcpy( ItemName[menu2][i], tmpBuffer );
strcpy( tmpBuffer, ActionToDo[menu1][i] );
strcpy( ActionToDo[menu1][i], ActionToDo[menu2][i] );
strcpy( ActionToDo[menu2][i], tmpBuffer );
strcpy( tmpBuffer, CmdLnArgs[menu1][i] );
strcpy( CmdLnArgs[menu1][i], CmdLnArgs[menu2][i] );
strcpy( CmdLnArgs[menu2][i], tmpBuffer );
strcpy( tmpBuffer, Directory[menu1][i] );
strcpy( Directory[menu1][i], Directory[menu2][i] );
strcpy( Directory[menu2][i], tmpBuffer );
t1 = ProgType[menu2][i];
ProgType[menu2][i] = ProgType[menu1][i];
ProgType[menu1][i] = t1;
}
t1 = NumItems[menu2];
NumItems[menu2] = NumItems[menu1];
NumItems[menu1] = t1;
strcpy( tmpBuffer, MenuName[menu1] );
strcpy( MenuName[menu1], MenuName[menu2] );
strcpy( MenuName[menu2], tmpBuffer );
UpdateMenu[menu1] = TRUE;
UpdateMenu[menu2] = TRUE;
WinSetMenuItemText( hwndMenu, 100+menu1*100, MenuName[menu1] );
WinSetMenuItemText( hwndMenu, 100+menu2*100, MenuName[menu2] );
}
////////////////////////////////////////////////////////////////////////////////
// AddAMenuProc - message handler for the dialog box that allows the user to
// add a menu to the menubar
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY AddAMenuProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop and put
// the current data into controls
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
WinSendDlgItemMsg( hWnd, MENUNAME, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXMENUNAMELENGTH-1, 0 ), 0 );
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// process a command message received from the system
//----------------------------------------------------------------------
case WM_COMMAND:
{
USHORT command = SHORT1FROMMP(mp1);
switch( command )
{
//--------------------------------------------------------------
// user press OK button. Add the menu name they entered into
// the menu structure and return
//--------------------------------------------------------------
case DID_OK: {
WinQueryDlgItemText( hWnd, MENUNAME, MAXMENUNAMELENGTH, MenuName[NumMenus]);
UpdateMenu[NumMenus] = TRUE;
NumItems[NumMenus] = 0;
menuData[NumMenus].afStyle = 0;
menuData[NumMenus].afAttribute = 0;
WinSendMsg( hwndMenu, MM_SETITEM, MPFROM2SHORT(100*NumMenus+100,TRUE),MPFROMP(&menuData[NumMenus]));
WinSetMenuItemText( hwndMenu, 100*NumMenus+100, &MenuName[NumMenus]);
MenuSelection = NumMenus;
NumMenus++;
WinDismissDlg( hWnd, TRUE );
return 0;
}
//--------------------------------------------------------------
// they decided not to add a menu, dismiss dialog and return
//--------------------------------------------------------------
case DID_CANCEL: {
WinDismissDlg( hWnd, TRUE );
return 0;
}
//--------------------------------------------------------------
// nothing we care about, pass on for default processing
//--------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
// ---------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
// ---------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// Swap menu items item1 and item2 on menu Menu in the menu information arrays
////////////////////////////////////////////////////////////////////////////////
VOID SwapTwoItems(SHORT Menu, SHORT item1, SHORT item2)
{
strcpy( tmpBuffer, ItemName[Menu][item2] );
strcpy( ItemName[Menu][item2], ItemName[Menu][item1] );
strcpy( ItemName[Menu][item1], tmpBuffer );
strcpy( tmpBuffer, ActionToDo[Menu][item2] );
strcpy( ActionToDo[Menu][item2], ActionToDo[Menu][item1] );
strcpy( ActionToDo[Menu][item1], tmpBuffer );
strcpy( tmpBuffer, CmdLnArgs[Menu][item2] );
strcpy( CmdLnArgs[Menu][item2], CmdLnArgs[Menu][item1] );
strcpy( CmdLnArgs[Menu][item1], tmpBuffer );
strcpy( tmpBuffer, Directory[Menu][item2] );
strcpy( Directory[Menu][item2], Directory[Menu][item1] );
strcpy( Directory[Menu][item1], tmpBuffer );
short t1 = ProgType[Menu][item2];
ProgType[Menu][item2] = ProgType[Menu][item1];
ProgType[Menu][item1] = t1;
}
////////////////////////////////////////////////////////////////////////////////
// updateItemList - refreshes the contents of the item list list-box in a dialog
////////////////////////////////////////////////////////////////////////////////
VOID updateItemList( HWND hWnd )
{
CHAR Separator[] = SEPARATOR;
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEALL, 0, 0 );
for (short i=0; i<NumItems[MenuSelection]; i++)
if (ItemName[MenuSelection][i][0] != '\0')
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
MPFROM2SHORT( LIT_END, 0 ),
ItemName[MenuSelection][i] );
else
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
MPFROM2SHORT( LIT_END, 0 ),
Separator );
if (NumItems[MenuSelection] > 0)
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
MPFROM2SHORT( ItemSelection, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
}
////////////////////////////////////////////////////////////////////////////////
// EditItemProc - the message handler for the edit menu item dialog box
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY EditItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop and put
// the current data into control fields
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
WinSendDlgItemMsg( hWnd, MENUNAME, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXMENUNAMELENGTH-1, 0 ), 0 );
WinSetDlgItemText( hWnd, MENUNAME, MenuName[MenuSelection]);
ItemSelection = 0;
updateItemList( hWnd );
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// if there is a control message, update enabled status of buttons
//----------------------------------------------------------------------
case WM_CONTROL:
{
if ((SHORT1FROMMP(mp1)==ITEMMENU) && (SHORT2FROMMP(mp1)==LN_ENTER))
return WinSendMsg( hWnd, WM_COMMAND, MPFROM2SHORT( CHANGEITEM, 0 ), mp2 );
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// process a command message received from the system
//----------------------------------------------------------------------
case WM_COMMAND:
{
USHORT command = SHORT1FROMMP(mp1);
switch( command )
{
//--------------------------------------------------------------
// insert a separator into item list, if there is room
//--------------------------------------------------------------
case INSERTSEPARATOR: {
ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
if (NumItems[MenuSelection] >= MAXITEMS-1) {
// error and return if no room
char text[]="Error! Maximum number of items for this menu already defined!";
char title[]="Add A Separator";
WinMessageBox( HWND_DESKTOP, hWnd, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
return 0;
}
// since this is a separator, blank out launch information
for (short i=NumItems[MenuSelection]-1; i>=ItemSelection; i--)
SwapTwoItems( MenuSelection, i, i+1 );
ItemName[MenuSelection][ItemSelection][0]='\0';
ActionToDo[MenuSelection][ItemSelection][0]='\0';
CmdLnArgs[MenuSelection][ItemSelection][0]='\0';
Directory[MenuSelection][ItemSelection][0]='\0';
ProgType[MenuSelection][ItemSelection]=0;
if (NumItems[MenuSelection]==0)
ItemSelection = 0;
NumItems[MenuSelection]++;
UpdateMenu[MenuSelection] = TRUE;
updateItemList( hWnd );
return 0;
}
//--------------------------------------------------------------
// user wants to add an item to the current menu
//--------------------------------------------------------------
case ADDITEM: {
ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
// error and return if no room for another item
if (NumItems[MenuSelection] >= MAXITEMS) {
char text[]="Error! Maximum number of items for this menu already defined!";
char title[]="Add An Item";
WinMessageBox( HWND_DESKTOP, hWnd, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
return 0;
}
// get new item via add item dialog box
WinDlgBox(HWND_DESKTOP,
hWnd,
(PFNWP)AddAnItemProc,
0,
ADDANITEM,
(PVOID)NULL);
// update item list with possible new item
updateItemList( hWnd );
return 0;
}
//--------------------------------------------------------------
// user wants to change a menu item
//--------------------------------------------------------------
case CHANGEITEM: {
ItemSelection = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
if ((NumItems[MenuSelection] == 0) || (ItemName[MenuSelection][ItemSelection][0] == '\0')) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
WinDlgBox(HWND_DESKTOP,
hWnd,
(PFNWP)EditItemDataProc,
0,
EDITITEMDATA,
(PVOID)NULL);
updateItemList( hWnd );
return 0;
}
//--------------------------------------------------------------
// move item down in menu order
//--------------------------------------------------------------
case MOVEITEMDOWN: {
CHAR Separator[] = SEPARATOR;
short i = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
if ((i == NumItems[MenuSelection]-1) || (NumItems[MenuSelection] == 0)) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
SwapTwoItems( MenuSelection, i, i+1 );
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
MPFROM2SHORT( i, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
if (ItemName[MenuSelection][i+1][0] == '\0')
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
MPFROM2SHORT( i+1, 0 ),
Separator );
else WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
MPFROM2SHORT( i+1, 0 ),
&ItemName[MenuSelection][i+1] );
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
MPFROM2SHORT( i+1, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
return 0;
}
//--------------------------------------------------------------
// move item up in menu order
//--------------------------------------------------------------
case MOVEITEMUP: {
CHAR Separator[] = SEPARATOR;
short i = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
if ((i == 0) || (NumItems[MenuSelection] == 0)) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
SwapTwoItems( MenuSelection, i-1, i );
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
MPFROM2SHORT( i, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
if (ItemName[MenuSelection][i-1][0] == '\0')
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
MPFROM2SHORT( i-1, 0 ),
Separator );
else WinSendDlgItemMsg( hWnd, ITEMMENU, LM_INSERTITEM,
MPFROM2SHORT( i-1, 0 ),
&ItemName[MenuSelection][i-1] );
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
MPFROM2SHORT( i-1, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
return 0;
}
//--------------------------------------------------------------
// remove a menu item
//--------------------------------------------------------------
case REMOVEITEM: {
char text[]="If you remove this item, there will be no way to recover it. Are you sure you want to remove this item?";
char title[]="Remove Menu Item";
if (NumItems[MenuSelection] == 0) {
WinAlarm(HWND_DESKTOP, WA_WARNING);
return 0;
}
if (NumItems[MenuSelection] > 0)
if (WinMessageBox( HWND_DESKTOP, hWnd, text, title, 0,
MB_MOVEABLE|MB_WARNING|MB_YESNO|MB_DEFBUTTON2) == MBID_YES ) {
short index = SHORT1FROMMP( WinSendDlgItemMsg( hWnd, ITEMMENU,
LM_QUERYSELECTION,
MPFROM2SHORT( LIT_FIRST, 0 ),
0 ) );
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_DELETEITEM,
MPFROM2SHORT( index, 0 ), 0 );
for (short i=index; i<MAXITEMS-1; i++) {
strcpy( ItemName[MenuSelection][i], ItemName[MenuSelection][i+1]);
strcpy( ActionToDo[MenuSelection][i], ActionToDo[MenuSelection][i+1]);
strcpy( CmdLnArgs[MenuSelection][i], CmdLnArgs[MenuSelection][i+1]);
strcpy( Directory[MenuSelection][i], Directory[MenuSelection][i+1]);
ProgType[MenuSelection][i] = ProgType[MenuSelection][i+1];
}
if (NumItems[MenuSelection] > 0) {
int newIndex = index-1;
if (0 > newIndex)
newIndex = 0;
if (index == NumItems[MenuSelection]-1)
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
MPFROM2SHORT( newIndex, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
else
WinSendDlgItemMsg( hWnd, ITEMMENU, LM_SELECTITEM,
MPFROM2SHORT( index, 0 ),
MPFROM2SHORT( TRUE, 0 ) );
}
NumItems[MenuSelection]--;
}
return 0;
}
//--------------------------------------------------------------
// user is done editing a menu, save menu name and return
//--------------------------------------------------------------
case DID_OK: {
WinQueryDlgItemText( hWnd, MENUNAME, MAXMENUNAMELENGTH, MenuName[MenuSelection]);
WinSetMenuItemText( hwndMenu, 100*MenuSelection+100, &MenuName[MenuSelection]);
UpdateMenu[MenuSelection] = TRUE;
WinDismissDlg( hWnd, TRUE );
return 0;
}
//--------------------------------------------------------------
// no message we care about, pass it onto the system
//--------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// update the enable/disabled state of the program type buttons
////////////////////////////////////////////////////////////////////////////////
void updateEditItemWindow( HWND hWnd )
{
int value = TRUE;
if (WinQueryButtonCheckstate( hWnd, STARTWPS ))
value = FALSE;
WinEnableControl( hWnd, MAXIMIZED, value );
WinEnableControl( hWnd, MINIMIZED, value );
WinEnableControl( hWnd, FOLDER, value );
WinEnableControl( hWnd, DOSWIN, value );
WinEnableControl( hWnd, DOSFS, value );
WinEnableControl( hWnd, OS2WIN, value );
WinEnableControl( hWnd, OS2FS, value );
WinEnableControl( hWnd, WINOS2WIN, value );
WinEnableControl( hWnd, WINOS2FS, value );
WinEnableControl( hWnd, PMAPP, value );
WinEnableControl( hWnd, SETTINGSBUTTON, TRUE-value );
if (WinQueryButtonCheckstate( hWnd, FOLDER )) {
WinEnableControl( hWnd, MAXIMIZED, FALSE );
WinEnableControl( hWnd, MINIMIZED, FALSE );
}
if ((WinQueryButtonCheckstate( hWnd, FOLDER )) || (WinQueryButtonCheckstate( hWnd, PMAPP )))
WinEnableControl( hWnd, STARTWPS, FALSE );
else
WinEnableControl( hWnd, STARTWPS, TRUE );
if (ActionToDo[MenuSelection][ItemSelection][0]=='\0')
WinEnableControl( hWnd, SETTINGSBUTTON, FALSE );
}
////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
void updateEditItemData( HWND hWnd )
{
// put item name and length of longest possible name in entry field
WinSendDlgItemMsg( hWnd, ITEMNAME, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXITEMNAMELENGTH-1, 0 ), 0 );
WinSetDlgItemText( hWnd, ITEMNAME, ItemName[MenuSelection][ItemSelection]);
// put path name and length of longest possible name in entry field
WinSendDlgItemMsg( hWnd, PATHNAME, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXACTIONSTRINGLENGTH-1, 0 ), 0 );
WinSetDlgItemText( hWnd, PATHNAME, ActionToDo[MenuSelection][ItemSelection]);
// put argument and length of longest possible in entry field
WinSendDlgItemMsg( hWnd, ARGUMENTS, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXARGSTRINGLENGTH-1, 0 ), 0 );
WinSetDlgItemText( hWnd, ARGUMENTS, CmdLnArgs[MenuSelection][ItemSelection]);
// put directory and length of longest possible directory in entry field
WinSendDlgItemMsg( hWnd, DIRECTORY, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXDIRSTRINGLENGTH-1, 0 ), 0 );
WinSetDlgItemText( hWnd, DIRECTORY, Directory[MenuSelection][ItemSelection]);
// set appropriate radio button for program startup option
WinCheckButton( hWnd, MAXIMIZED, FALSE );
WinCheckButton( hWnd, MINIMIZED, FALSE );
if (ProgType[MenuSelection][ItemSelection] & STARTMAX)
WinCheckButton( hWnd, MAXIMIZED, TRUE );
else if (ProgType[MenuSelection][ItemSelection] & STARTMIN)
WinCheckButton( hWnd, MINIMIZED, TRUE );
// set appropriate radio button for program startup option
if (ProgType[MenuSelection][ItemSelection] & PM)
WinCheckButton( hWnd, PMAPP, TRUE );
else if (ProgType[MenuSelection][ItemSelection] & WPSFOLDER)
WinCheckButton( hWnd, FOLDER, TRUE );
else if ( (ProgType[MenuSelection][ItemSelection] & DOS) &&
(ProgType[MenuSelection][ItemSelection] & WINDOWED))
WinCheckButton( hWnd, DOSWIN, TRUE );
else if ( (ProgType[MenuSelection][ItemSelection] & DOS) &&
(ProgType[MenuSelection][ItemSelection] & FULLSCREEN))
WinCheckButton( hWnd, DOSFS, TRUE );
else if ( (ProgType[MenuSelection][ItemSelection] & OS2) &&
(ProgType[MenuSelection][ItemSelection] & WINDOWED))
WinCheckButton( hWnd, OS2WIN, TRUE );
else if ( (ProgType[MenuSelection][ItemSelection] & OS2) &&
(ProgType[MenuSelection][ItemSelection] & FULLSCREEN))
WinCheckButton( hWnd, OS2FS, TRUE );
else if ( (ProgType[MenuSelection][ItemSelection] & WINOS2) &&
(ProgType[MenuSelection][ItemSelection] & WINDOWED))
WinCheckButton( hWnd, WINOS2WIN, TRUE );
else if ( (ProgType[MenuSelection][ItemSelection] & WINOS2) &&
(ProgType[MenuSelection][ItemSelection] & FULLSCREEN))
WinCheckButton( hWnd, WINOS2FS, TRUE );
if (ProgType[MenuSelection][ItemSelection] & STARTASWPS)
WinCheckButton( hWnd, STARTWPS, TRUE );
else
WinCheckButton( hWnd, STARTWPS, FALSE );
updateEditItemWindow( hWnd );
}
////////////////////////////////////////////////////////////////////////////////
// message handler for the dialog "edit an item's values"
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY EditItemDataProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// if the object being drug over us is a single folder, allow drag
//----------------------------------------------------------------------
case DM_DRAGOVER: {
ULONG cbBuffer;
DRAGITEM dragItem;
PDRAGINFO dragInfoPtr;
int numObjects;
dragInfoPtr = (PDRAGINFO)mp1;
DrgAccessDraginfo(dragInfoPtr);
numObjects = dragInfoPtr->cditem;
cbBuffer = sizeof(DRAGITEM);
DrgQueryDragitem( dragInfoPtr, cbBuffer, &dragItem, 0 );
DrgFreeDraginfo(dragInfoPtr);
if ((numObjects == 1) && (dragItem.fsControl & DC_CONTAINER))
return MPFROM2SHORT( DOR_DROP, DO_UNKNOWN );
return MPFROM2SHORT( DOR_NEVERDROP, DO_UNKNOWN );
}
//----------------------------------------------------------------------
// allow the dropping of a WPS folder to our window. Once dropped, get
// necessary info and fill in dialog with the info we retrieve
//----------------------------------------------------------------------
case DM_DROP: {
PDRAGINFO dragInfoPtr;
ULONG cbBuffer;
DRAGITEM dragItem;
dragInfoPtr = (PDRAGINFO)mp1;
DrgAccessDraginfo(dragInfoPtr);
cbBuffer = sizeof(DRAGITEM);
DrgQueryDragitem( dragInfoPtr, cbBuffer, &dragItem, 0 );
// get menu item name
DrgQueryStrName( dragItem.hstrTargetName, sizeof(ItemName[MenuSelection][ItemSelection]), ItemName[MenuSelection][ItemSelection]);
// get default directory
DrgQueryStrName( dragItem.hstrContainerName, sizeof(Directory[MenuSelection][ItemSelection]), Directory[MenuSelection][ItemSelection]);
// get path name
DrgQueryStrName( dragItem.hstrSourceName, sizeof(ActionToDo[MenuSelection][ItemSelection]), ActionToDo[MenuSelection][ItemSelection]);
ProgType[MenuSelection][ItemSelection] = WPSFOLDER;
WinCheckButton( hWnd, FOLDER, TRUE );
DrgFreeDraginfo(dragInfoPtr);
updateEditItemData( hWnd );
WinSetFocus( HWND_DESKTOP, hWnd );
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop and put
// the current data into control fields
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
// center dialog on screen
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
// save data in case of cancel or restore
oldProgType = ProgType[MenuSelection][ItemSelection];
strcpy( oldItemName, ItemName[MenuSelection][ItemSelection] );
strcpy( oldDirectory, Directory[MenuSelection][ItemSelection] );
strcpy( oldAction, ActionToDo[MenuSelection][ItemSelection] );
strcpy( oldCmdLn, CmdLnArgs[MenuSelection][ItemSelection] );
updateEditItemData( hWnd );
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// we received a control message, update enabling of buttons
//----------------------------------------------------------------------
case WM_CONTROL:
{
if ((SHORT1FROMMP(mp1)==MAXIMIZED) && (SHORT2FROMMP(mp1)==BN_CLICKED))
WinCheckButton( hWnd, MINIMIZED, FALSE );
if ((SHORT1FROMMP(mp1)==MINIMIZED) && (SHORT2FROMMP(mp1)==BN_CLICKED))
WinCheckButton( hWnd, MAXIMIZED, FALSE );
updateEditItemWindow( hWnd ); return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// process a command message received from the system
//----------------------------------------------------------------------
case WM_COMMAND:
{
USHORT command = SHORT1FROMMP(mp1);
switch( command )
{
//--------------------------------------------------------------
// open the settings notebook and allow user modifications
//--------------------------------------------------------------
case SETTINGSBUTTON: {
RXSTRING retstr;
RXSTRING INSTORE[2];
SHORT returnCode;
char mesg[1024];
int offset;
short rc;
// open settings for current program in dialog controls
WinQueryDlgItemText( hWnd, ITEMNAME, MAXITEMNAMELENGTH,
ItemName[MenuSelection][ItemSelection]);
WinQueryDlgItemText( hWnd, PATHNAME, MAXACTIONSTRINGLENGTH,
ActionToDo[MenuSelection][ItemSelection]);
WinQueryDlgItemText( hWnd, ARGUMENTS, MAXARGSTRINGLENGTH,
CmdLnArgs[MenuSelection][ItemSelection]);
WinQueryDlgItemText( hWnd, DIRECTORY, MAXDIRSTRINGLENGTH,
Directory[MenuSelection][ItemSelection]);
offset = 0;
offset = offset + sprintf(mesg+offset, "/* */\r\n");
offset = offset + sprintf(mesg+offset, "call RxFuncAdd 'SysSetObjectData', 'RexxUtil', 'SysSetObjectData'\r\n");
if (ProgType[MenuSelection][ItemSelection] & WPSFOLDER)
offset = offset + sprintf(mesg+offset, "result = SysSetObjectData(\"%s%s\",\"OPEN=SETTINGS\")\r\n\x1A\0", Directory[MenuSelection][ItemSelection],ActionToDo[MenuSelection][ItemSelection]);
else
offset = offset + sprintf(mesg+offset, "result = SysSetObjectData(\"%s\",\"OPEN=SETTINGS\")\r\n\x1A\0", ActionToDo[MenuSelection][ItemSelection]);
INSTORE[0].strptr=mesg;
INSTORE[0].strlength=strlen(mesg);
INSTORE[1].strptr=NULL;
INSTORE[1].strlength=0;
rc = rexxStart((LONG)0,
(PRXSTRING)0,
(PSZ)LAUNCHFILE,
(PRXSTRING)INSTORE,
(PSZ)"CMD",
(LONG)RXCOMMAND,
(PRXSYSEXIT)0,
(SHORT*)&returnCode,
(PRXSTRING)&retstr);
if ((rc) || (returnCode)) {
char title[]="Open Settings for Object";
char mesg[]="Could not locate the settings for this object. You may consider fully qualifying (adding drive and path) the program and trying again.";
WinMessageBox( HWND_DESKTOP, hWnd, mesg, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
return 0;
}
//--------------------------------------------------------------
// the user wants to find a file to call as a menu item. Hook
// into OS/2's file dialog procedure to ease the finding process
// for us to program! Then once a file is selected, fill in
// the program path, directory and query the application for its
// application type and mark the appropriate radio button
//--------------------------------------------------------------
case FINDFILE: {
CHAR title[] = "FileBar - Find A File To Add";
ULONG s, t;
HWND hwndDialog;
fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
fileDlgInfo.pszTitle = title;
strcat(fileDlgInfo.szFullFile, "*.*\0");
hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
strcpy( ActionToDo[MenuSelection][ItemSelection], fileDlgInfo.szFullFile );
s=0;
while(fileDlgInfo.szFullFile[s]!='\0')
s++;
while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
s--;
t = 0;
while (t<s)
Directory[MenuSelection][ItemSelection][t] = fileDlgInfo.szFullFile[t++];
Directory[MenuSelection][ItemSelection][t] = '\0';
DosQueryAppType( ActionToDo[MenuSelection][ItemSelection], &t);
ProgType[MenuSelection][ItemSelection] = OS2 + WINDOWED;
if (t == FAPPTYP_WINDOWAPI)
ProgType[MenuSelection][ItemSelection] = PM;
if (t == FAPPTYP_WINDOWCOMPAT)
ProgType[MenuSelection][ItemSelection] = OS2 + WINDOWED;
if (t == FAPPTYP_NOTWINDOWCOMPAT)
ProgType[MenuSelection][ItemSelection] = OS2 + FULLSCREEN;
if (t == FAPPTYP_DOS)
ProgType[MenuSelection][ItemSelection] = DOS + WINDOWED;
if ((t == FAPPTYP_WINDOWSREAL) || (t == FAPPTYP_WINDOWSPROT))
ProgType[MenuSelection][ItemSelection] = WINOS2 + FULLSCREEN;
updateEditItemData( hWnd );
updateEditItemWindow( hWnd );
if (fileDlgInfo.szFullFile[s]=='\\')
fileDlgInfo.szFullFile[s+1]='\0';
else
fileDlgInfo.szFullFile[0]='\0';
}
else
fileDlgInfo.szFullFile[0]='\0';
return 0;
}
//--------------------------------------------------------------
// user pressed Reset, restore old settings and continue
//--------------------------------------------------------------
case RESETBUTTON: {
ProgType[MenuSelection][ItemSelection] = oldProgType;
strcpy( ItemName[MenuSelection][ItemSelection], oldItemName );
strcpy( Directory[MenuSelection][ItemSelection], oldDirectory );
strcpy( ActionToDo[MenuSelection][ItemSelection], oldAction );
strcpy( CmdLnArgs[MenuSelection][ItemSelection], oldCmdLn );
updateEditItemData( hWnd );
return 0;
}
//--------------------------------------------------------------
// user pressed CANCEL, restore old item data
//--------------------------------------------------------------
case DID_CANCEL: {
ProgType[MenuSelection][ItemSelection] = oldProgType;
strcpy( ItemName[MenuSelection][ItemSelection], oldItemName );
strcpy( Directory[MenuSelection][ItemSelection], oldDirectory );
strcpy( ActionToDo[MenuSelection][ItemSelection], oldAction );
strcpy( CmdLnArgs[MenuSelection][ItemSelection], oldCmdLn );
WinDismissDlg( hWnd, TRUE );
return 0;
}
//--------------------------------------------------------------
// user pressed OK, save current information for this item
//--------------------------------------------------------------
case DID_OK: {
if ( WinQueryButtonCheckstate( hWnd, MAXIMIZED ) &&
WinQueryButtonCheckstate( hWnd, MINIMIZED ) ) {
char text[]="Cannot have the item start both as minimized AND maximized!";
WinMessageBox( HWND_DESKTOP, hWnd, text, NULL, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
return 0;
}
// save program type and max/min startup status
ProgType[MenuSelection][ItemSelection] = 0;
if (WinQueryButtonCheckstate( hWnd, FOLDER ))
ProgType[MenuSelection][ItemSelection] = WPSFOLDER;
if (WinQueryButtonCheckstate( hWnd, OS2WIN ))
ProgType[MenuSelection][ItemSelection] = OS2 + WINDOWED;
if (WinQueryButtonCheckstate( hWnd, OS2FS ))
ProgType[MenuSelection][ItemSelection] = OS2 + FULLSCREEN;
if (WinQueryButtonCheckstate( hWnd, DOSWIN ))
ProgType[MenuSelection][ItemSelection] = DOS + WINDOWED;
if (WinQueryButtonCheckstate( hWnd, DOSFS ))
ProgType[MenuSelection][ItemSelection] = DOS + FULLSCREEN;
if (WinQueryButtonCheckstate( hWnd, WINOS2WIN ))
ProgType[MenuSelection][ItemSelection] = WINOS2 + WINDOWED;
if (WinQueryButtonCheckstate( hWnd, WINOS2FS ))
ProgType[MenuSelection][ItemSelection] = WINOS2 + FULLSCREEN;
if (WinQueryButtonCheckstate( hWnd, PMAPP ))
ProgType[MenuSelection][ItemSelection] = PM;
if (WinQueryButtonCheckstate( hWnd, MAXIMIZED ))
ProgType[MenuSelection][ItemSelection] = ProgType[MenuSelection][ItemSelection] | STARTMAX;
if (WinQueryButtonCheckstate( hWnd, MINIMIZED ))
ProgType[MenuSelection][ItemSelection] = ProgType[MenuSelection][ItemSelection] | STARTMIN;
if (WinQueryButtonCheckstate( hWnd, STARTWPS ))
ProgType[MenuSelection][ItemSelection] = ProgType[MenuSelection][ItemSelection] | STARTASWPS;
// save name, path, directory, command line args
WinQueryDlgItemText( hWnd, ITEMNAME, MAXITEMNAMELENGTH,
ItemName[MenuSelection][ItemSelection]);
WinQueryDlgItemText( hWnd, PATHNAME, MAXACTIONSTRINGLENGTH,
ActionToDo[MenuSelection][ItemSelection]);
WinQueryDlgItemText( hWnd, ARGUMENTS, MAXARGSTRINGLENGTH,
CmdLnArgs[MenuSelection][ItemSelection]);
WinQueryDlgItemText( hWnd, DIRECTORY, MAXDIRSTRINGLENGTH,
Directory[MenuSelection][ItemSelection]);
UpdateMenu[MenuSelection] = TRUE;
WinDismissDlg( hWnd, TRUE );
return 0;
}
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// AddAnItemProc - the message handler for the "add an item to a menu" dialog
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY AddAnItemProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop and put
// the current data into control fields
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
WinSendDlgItemMsg( hWnd, ITEMNAME, EM_SETTEXTLIMIT,
MPFROM2SHORT( MAXITEMNAMELENGTH-1, 0 ), 0 );
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// process a command message received from the system
//----------------------------------------------------------------------
case WM_COMMAND:
{
USHORT command = SHORT1FROMMP(mp1);
switch( command )
{
//--------------------------------------------------------------
// if they pressed OK, then save the data in the dialog as an
// item that we can now launch from the fileBar.
//--------------------------------------------------------------
case DID_OK: {
WinQueryDlgItemText( hWnd, ITEMNAME, MAXMENUNAMELENGTH, ItemName[MenuSelection][ (NumItems[MenuSelection]) ]);
ActionToDo[MenuSelection][ (NumItems[MenuSelection]) ][0] = '\0';
CmdLnArgs[MenuSelection][ (NumItems[MenuSelection]) ][0] = '\0';
Directory[MenuSelection][ (NumItems[MenuSelection]) ][0] = '\0';
ProgType[MenuSelection][ (NumItems[MenuSelection]) ] = PM;
UpdateMenu[MenuSelection] = TRUE;
WinDismissDlg( hWnd, TRUE );
ItemSelection = NumItems[MenuSelection];
NumItems[MenuSelection]++;
WinDlgBox(HWND_DESKTOP,
hWnd,
(PFNWP)EditItemDataProc,
0,
EDITITEMDATA,
(PVOID)NULL);
return 0;
}
//--------------------------------------------------------------
// if they pressed cancel, save no data and return
//--------------------------------------------------------------
case DID_CANCEL: {
WinDismissDlg( hWnd, TRUE );
return 0;
}
//--------------------------------------------------------------
// nothing further we care about, pass on for default processing
//--------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// Message handler for a generic information-only dialog box (help & prod info)
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY EnterParamProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
WinSetWindowText( hWnd, parameterTitle );
WinSetDlgItemText( hWnd, PARAMETER_TEXT, ParameterTextPtr );
WinSendDlgItemMsg( hWnd, PARAMETER_TEXT, EM_SETTEXTLIMIT, MPFROMSHORT( sizeof(variableText) ), 0 );
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
// if we receive any system message, dismiss the dialog box
//----------------------------------------------------------------------
case WM_COMMAND:
{
WinQueryDlgItemText( hWnd, PARAMETER_EDIT, sizeof(variableText), (PSZ)variableText );
WinDismissDlg( hWnd, TRUE );
return 0;
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}
////////////////////////////////////////////////////////////////////////////////
// startApplication uses DosStartSession to start a batch file to start an
// application pointed to in one of the user menus by menu and item variables.
////////////////////////////////////////////////////////////////////////////////
SHORT startApplication( SHORT menu, SHORT item )
{
CHAR parameters[MAXARGSTRINGLENGTH];
CHAR itemName[MAXITEMNAMELENGTH];
RXSTRING INSTORE[2];
RXSTRING retstr;
APIRET rc;
STARTDATA startData;
ULONG sessionId;
PID ppId;
UCHAR ObjBuf[2];
SHORT ReturnCode;
LONG offset;
{
short y1=0;
short y2=0;
while (ItemName[menu][item][y1]!='\0') {
if (ItemName[menu][item][y1]!='~')
itemName[y2++] = ItemName[menu][item][y1];
y1++;
}
itemName[y2] = '\0';
}
{
short i = 0;
short h = 0;
while ( CmdLnArgs[menu][item][i] != '\0' ) {
if (CmdLnArgs[menu][item][i] == STARTINPUT) {
short j = 0;
CHAR tmp[MAXARGSTRINGLENGTH];
i++;
while ( (CmdLnArgs[menu][item][i] != '\0') &&
(CmdLnArgs[menu][item][i] != ENDINPUT ))
tmp[j++] = CmdLnArgs[menu][item][i++];
tmp[j] = '\0';
if (CmdLnArgs[menu][item][i] != '\0')
i++;
parameters[h++] = '*';
{
CHAR mesg[512];
SHORT k = 0;
sprintf( parameterTitle, "%s parameter...", ItemName[menu][item] );
sprintf( mesg, "Please enter '%s'", tmp);
ParameterTextPtr = mesg;
(VOID*)WinDlgBox(HWND_DESKTOP,
hwndFrame,
(PFNWP)EnterParamProc,
0,
ENTERPARAMETER,
(PVOID)NULL);
while ( variableText[k] != '\0')
parameters[h++] = variableText[k++];
}
parameters[h++] = '*';
}
else
parameters[h++] = CmdLnArgs[menu][item][i++];
}
parameters[h] = '\0';
}
//--------------------------------------------------------------------------
// open a WPS folder/object
//--------------------------------------------------------------------------
if ((ProgType[menu][item] & WPSFOLDER) || (ProgType[menu][item] & STARTASWPS)) {
char mesg[CCHMAXPATH+CCHMAXPATH+256];
offset = 0;
offset = offset + sprintf(mesg+offset, "/* */\r\n");
offset = offset + sprintf(mesg+offset, "call RxFuncAdd 'SysSetObjectData', 'RexxUtil', 'SysSetObjectData'\r\n");
if (ProgType[menu][item] & WPSFOLDER)
offset = offset + sprintf(mesg+offset, "result = SysSetObjectData(\"%s%s\",\"OPEN=DEFAULT\")\r\n", Directory[menu][item],ActionToDo[menu][item]);
else
offset = offset + sprintf(mesg+offset, "result = SysSetObjectData(\"%s\",\"OPEN=DEFAULT\")\r\n", ActionToDo[menu][item]);
offset = offset + sprintf(mesg+offset, "\x1A\0");
INSTORE[0].strptr=mesg;
INSTORE[0].strlength=strlen(mesg);
INSTORE[1].strptr=NULL;
INSTORE[1].strlength=0;
rc = rexxStart((LONG)0,
(PRXSTRING)0,
(PSZ)LAUNCHFILE,
(PRXSTRING)INSTORE,
(PSZ)"CMD",
(LONG)RXCOMMAND,
(PRXSYSEXIT)0,
(SHORT*)&ReturnCode,
(PRXSTRING)&retstr);
if (!rc) {
ULONG numItems;
ULONG Buffer;
PSWBLOCK SwitchBlockPtr;
HSWITCH hSwitch;
numItems = WinQuerySwitchList( hab, NULL, 0 );
Buffer = (numItems * sizeof(SWENTRY)) + sizeof(HSWITCH);
PVOID my = new BYTE[Buffer];
WinQuerySwitchList( hab, (SWBLOCK*)my, Buffer );
SwitchBlockPtr = (PSWBLOCK)(my);
hSwitch = WinQuerySwitchHandle( SwitchBlockPtr->aswentry[numItems-1].swctl.hwnd,
SwitchBlockPtr->aswentry[numItems-1].swctl.idProcess);
delete( my );
rc = WinSwitchToProgram( hSwitch );
}
return rc;
}
//--------------------------------------------------------------------------
// launch a windows app
//--------------------------------------------------------------------------
// if ((ProgType[menu][item] & WINOS2) && (ProgType[menu][item] & WINDOWED)) {
if (ProgType[menu][item] & WINOS2) {
FILE* outputFile;
STARTDATA startData;
outputFile = fopen(LAUNCHFILE, "wt");
if (!outputFile) {
char title[] = "Launch an application";
char text[] = "Could not start the application due to an error accessing the drive";
WinMessageBox( HWND_DESKTOP, hwndFrame, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
return 0;
}
if (Directory[menu][item][0] != '\0') {
if ((isalpha( Directory[menu][item][0] )) && ( Directory[menu][item][1]==':'))
fprintf( outputFile, "%c:\n", Directory[menu][item][0]);
fprintf( outputFile, "cd %s\n", Directory[menu][item]);
}
fprintf( outputFile, "start /C " );
if (ProgType[menu][item] & STARTMAX)
fprintf( outputFile, "/MAX ");
else if (ProgType[menu][item] & STARTMIN)
fprintf( outputFile, "/MIN ");
if (ProgType[menu][item] & WINDOWED)
fprintf( outputFile, "/WIN ");
else if (ProgType[menu][item] & FULLSCREEN)
fprintf( outputFile, "/FS ");
fprintf( outputFile, "%s %s", ActionToDo[menu][item], parameters );
fclose( outputFile );
{
CHAR title[] = "FileBar -\nWIN-OS/2 Launch";
CHAR program[] = OS2SHELL;
CHAR inputs[] = LAUNCHINPUTS;
memset( &startData, 0, sizeof(STARTDATA) );
startData.Related = SSF_RELATED_INDEPENDENT;
startData.FgBg = SSF_FGBG_FORE;
startData.TraceOpt = SSF_TRACEOPT_NONE;
startData.InheritOpt = SSF_INHERTOPT_PARENT;
startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
startData.PgmControl = SSF_CONTROL_INVISIBLE | SSF_CONTROL_MINIMIZE;
startData.PgmTitle = title;
startData.PgmName = program;
startData.PgmInputs = inputs;
startData.ObjectBuffer = ObjBuf;
startData.ObjectBuffLen = sizeof(ObjBuf);
startData.Length = sizeof(STARTDATA);
return DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
(PID*) &ppId );
}
}
//--------------------------------------------------------------------------
/*
//// this doesn't work to start a seamless app and I don't know why!! :(
if ((ProgType[menu][item] & WINOS2) && (ProgType[menu][item] & WINDOWED)) {
APIRET rc;
PROGDETAILS pDetails;
memset( &pDetails, 0, sizeof(PROGDETAILS) );
pDetails.Length = sizeof(PROGDETAILS);
pDetails.progt.progc = PROG_WINDOWABLEVIO;
pDetails.progt.fbVisible = SHE_VISIBLE;
pDetails.pszTitle = 0; //ItemName[menu][item];
pDetails.pszExecutable = "\\os2\\te2\\te2.exe"; //ActionToDo[menu][item];
//pDetails.pszParameters = "";
//pDetails.pszIcon = "C:\\OS2\\FILEBAR\\FILEBAR.ICO";
//pDetails.pszEnvironment = "WORKPLACE\0\0";
//pDetails.pszParameters = CmdLnArgs[menu][item];
//pDetails.pszStartupDir = "d:\os2\mdos\winos2"; //Directory[menu][item];
pDetails.swpInitial.fl = SWP_ACTIVATE;
if (ProgType[menu][item] & STARTMAX)
rc = WinStartApp(NULLHANDLE, &pDetails, CmdLnArgs[menu][item], NULL, 4 );
else if (ProgType[menu][item] & STARTMIN)
rc = WinStartApp(NULLHANDLE, &pDetails, CmdLnArgs[menu][item], NULL, 8 );
else rc = WinStartApp(NULLHANDLE, &pDetails, CmdLnArgs[menu][item], NULL, 0 );
if (rc==0) {
ERRORID errorID = WinGetLastError( hab );
char text[1024];
sprintf(text, "error code %lu\0", errorID);
WinMessageBox( HWND_DESKTOP, hwndFrame, text, NULL, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
return 0;
}
*/
//--------------------------------------------------------------------------
// this launches a command shell (DOS or OS2 (Windowed or FS session))
//--------------------------------------------------------------------------
if (ActionToDo[menu][item][0] == '\0') {
ULONG currentDrive;
ULONG driveMap;
CHAR InputDir[CCHMAXPATH + 16];
DosQueryCurrentDisk( ¤tDrive, &driveMap );
DosSetDefaultDisk( (ULONG)(toupper(Directory[menu][item][0])-'A' + 1) );
memset( &startData, 0, sizeof(STARTDATA) );
startData.Related = SSF_RELATED_INDEPENDENT;
startData.FgBg = SSF_FGBG_FORE;
startData.TraceOpt = SSF_TRACEOPT_NONE;
startData.InheritOpt = SSF_INHERTOPT_PARENT;
startData.ObjectBuffer = ObjBuf;
startData.ObjectBuffLen = sizeof(ObjBuf);
startData.Length = sizeof(STARTDATA);
startData.PgmTitle = itemName;
strcpy( InputDir, "/K cd \0");
strcpy( InputDir+6, Directory[menu][item] );
startData.PgmInputs = InputDir;
startData.PgmControl = SSF_CONTROL_VISIBLE;
if (ProgType[menu][item] & MAXIMIZED)
startData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MAXIMIZE;
else if (ProgType[menu][item] & MINIMIZED)
startData.PgmControl = SSF_CONTROL_VISIBLE | SSF_CONTROL_MINIMIZE;
if (ProgType[menu][item] & DOS) {
if (ProgType[menu][item] & WINDOWED)
startData.SessionType = SSF_TYPE_WINDOWEDVDM;
else
startData.SessionType = SSF_TYPE_VDM;
rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
(PID*) &ppId );
DosSetDefaultDisk( currentDrive );
return rc;
}
else if (ProgType[menu][item] & OS2) {
if (ProgType[menu][item] & WINDOWED)
startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
else
startData.SessionType = SSF_TYPE_FULLSCREEN;
rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
(PID*) &ppId );
DosSetDefaultDisk( currentDrive );
return rc;
}
DosBeep(100,200);
return 0;
}
//--------------------------------------------------------------------------
// this section of code launches a program (non-command shell application)
//--------------------------------------------------------------------------
{
APIRET rc;
ULONG currentDrive;
ULONG driveMap;
UCHAR defaultDirectory[CCHMAXPATH];
CHAR title[MAXITEMNAMELENGTH];
CHAR program[CCHMAXPATH];
CHAR inputs[MAXARGSTRINGLENGTH];
strcpy(program, ActionToDo[menu][item]);
strcpy(inputs, parameters );
strcpy(title, ItemName[menu][item]);
memset( &startData, 0, sizeof(STARTDATA) );
startData.Length = sizeof(STARTDATA);
startData.Related = SSF_RELATED_INDEPENDENT;
startData.FgBg = SSF_FGBG_FORE;
startData.TraceOpt = SSF_TRACEOPT_NONE;
startData.PgmTitle = itemName;
startData.InheritOpt = SSF_INHERTOPT_PARENT;
startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
startData.PgmControl = SSF_CONTROL_VISIBLE;
startData.SessionType = SSF_TYPE_PM;
startData.PgmName = program;
startData.PgmInputs = inputs;
if (ProgType[menu][item] & DOS) {
if (ProgType[menu][item] & FULLSCREEN)
startData.SessionType = SSF_TYPE_VDM;
else if (ProgType[menu][item] & WINDOWED)
startData.SessionType = SSF_TYPE_WINDOWEDVDM;
}
else if (ProgType[menu][item] & OS2) {
if (ProgType[menu][item] & FULLSCREEN)
startData.SessionType = SSF_TYPE_FULLSCREEN;
else if (ProgType[menu][item] & WINDOWED)
startData.SessionType = SSF_TYPE_WINDOWABLEVIO;
}
else if (ProgType[menu][item] & WINOS2)
startData.SessionType = SSF_TYPE_FULLSCREEN;
if (ProgType[menu][item] & STARTMAX)
startData.PgmControl |= SSF_CONTROL_MAXIMIZE;
else if (ProgType[menu][item] & STARTMIN)
startData.PgmControl |= SSF_CONTROL_MINIMIZE;
if ((startData.PgmName != NULL) && (startData.SessionType != SSF_TYPE_PM)) {
CHAR temp[CCHMAXPATH*2+5];
sprintf(temp, "/c %s %s\0", program, inputs);
startData.PgmName = 0;
strcpy(inputs, temp);
startData.PgmInputs = inputs;
}
// save current drive and directory
DosQueryCurrentDisk( ¤tDrive, &driveMap );
{
CHAR temp[CCHMAXPATH+5];
ULONG tempSize = CCHMAXPATH;
defaultDirectory[0]= (currentDrive+'A'-1);
defaultDirectory[1]= ':';
defaultDirectory[2]= '\\';
defaultDirectory[3]= '\0';
DosQueryCurrentDir( currentDrive, (CHAR*)&temp, &tempSize );
strcat( defaultDirectory, temp );
}
// point to working directory of program to execute
if (((toupper(Directory[menu][item][0]))>='A') && ((toupper(Directory[menu][item][0]))<='Z'))
DosSetDefaultDisk( (ULONG)(toupper(Directory[menu][item][0])-'A' + 1) );
DosSetCurrentDir( Directory[menu][item] );
rc = DosStartSession( (STARTDATA*) &startData, (ULONG*)&sessionId,
(PID*) &ppId );
// restore current drive and directory
DosSetDefaultDisk( currentDrive );
DosSetCurrentDir( defaultDirectory );
if (rc != 0) {
char text[] = "Could not open the specified item. Path and directory information may not be correct.";
char title[32];
sprintf( title, "FileBar Launch Error");
WinMessageBox( HWND_DESKTOP, hwndFrame, text, title, 0,
MB_MOVEABLE|MB_ERROR|MB_OK);
}
return rc;
}
}
////////////////////////////////////////////////////////////////////////////////
// display a background bitmap
////////////////////////////////////////////////////////////////////////////////
VOID displayBackground( VOID )
{
DESKTOP desktop;
if ((showBackground) || (isBackgroundDisplayed)) {
desktop.cbSize = sizeof( DESKTOP );
desktop.hbm = 0;
desktop.x = 0;
desktop.y = 0;
desktop.fl = SDT_DESTROY;
if (isBackgroundDisplayed)
WinSetDesktopBkgnd( HWND_DESKTOP, &desktop );
desktop.fl = SDT_LOADFILE;
if (backgroundAttr & SCALED)
desktop.fl = SDT_SCALE|SDT_LOADFILE;
if (backgroundAttr & TILED) {
desktop.fl = SDT_TILE|SDT_LOADFILE;
desktop.lTileCount = backgroundAttr - TILED;
}
strcpy( desktop.szFile, backgroundBitmap );
if (showBackground) {
WinSetDesktopBkgnd( HWND_DESKTOP, &desktop );
isBackgroundDisplayed = TRUE;
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Message handler for a generic information-only dialog box (help & prod info)
////////////////////////////////////////////////////////////////////////////////
MRESULT EXPENTRY backgroundProc(HWND hWnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
switch( msg )
{
//----------------------------------------------------------------------
// when the dialog is being initialized, center it on desktop
//----------------------------------------------------------------------
case WM_INITDLG: {
SWP swp;
char temp[12];
WinCheckButton( hWnd, BKGND_NORMAL, TRUE );
if (backgroundAttr & SCALED)
WinCheckButton( hWnd, BKGND_SCALED, TRUE );
else if (backgroundAttr & TILED) {
WinCheckButton( hWnd, BKGND_TILED, TRUE );
WinEnableControl( hWnd, BKGND_TILENUMBER, TRUE );
WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, TRUE );
WinEnableControl( hWnd, BKGND_LESS, TRUE );
WinEnableControl( hWnd, BKGND_MORE, TRUE );
}
if (backgroundAttr & SCALED)
backgroundAttr = backgroundAttr - SCALED;
if (backgroundAttr & TILED)
backgroundAttr = backgroundAttr - TILED;
sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
WinSendDlgItemMsg( hWnd, BKGND_BITMAPNAME, EM_SETTEXTLIMIT, MPFROMSHORT( sizeof(backgroundBitmap) ), 0 );
WinSetDlgItemText( hWnd, BKGND_BITMAPNAME, backgroundBitmap );
WinCheckButton( hWnd, BKGND_SHOW, showBackground );
WinQueryWindowPos( hWnd, (PSWP)&swp);
WinSetWindowPos( hWnd, (HWND)0,
((SHORT)((ScreenSizeX-swp.cx)/2)),
((SHORT)((ScreenSizeY-swp.cy)/2)),
0, 0, SWP_MOVE);
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
case WM_CONTROL:
{
if (SHORT2FROMMP(mp1)==BN_CLICKED) {
BOOL option = FALSE;
if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
option = TRUE;
WinEnableControl( hWnd, BKGND_TILENUMBER, option );
WinEnableControl( hWnd, BKGND_TILENUMBERTEXT, option );
WinEnableControl( hWnd, BKGND_LESS, option );
WinEnableControl( hWnd, BKGND_MORE, option );
}
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
//----------------------------------------------------------------------
//----------------------------------------------------------------------
case WM_COMMAND:
{
USHORT command = SHORT1FROMMP(mp1);
switch( command )
{
//--------------------------------------------------------------
// if they pressed OK, then save the data in the dialog as an
// item that we can now launch from the fileBar.
//--------------------------------------------------------------
case DID_OK: {
WinQueryDlgItemText( hWnd, BKGND_BITMAPNAME, sizeof(backgroundBitmap), (PSZ)backgroundBitmap );
showBackground = WinQueryButtonCheckstate( hWnd, BKGND_SHOW );
if (WinQueryButtonCheckstate( hWnd, BKGND_SCALED))
backgroundAttr = backgroundAttr + SCALED;
if (WinQueryButtonCheckstate( hWnd, BKGND_TILED))
backgroundAttr = backgroundAttr + TILED;
WinDismissDlg( hWnd, TRUE );
return 0;
}
case BKGND_LESS: {
char temp[12];
if (backgroundAttr > 1)
backgroundAttr--;
sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
return 0;
}
case BKGND_MORE: {
char temp[12];
if (backgroundAttr < 32)
backgroundAttr++;
sprintf(temp,"%d x %d", backgroundAttr, backgroundAttr);
WinSetDlgItemText( hWnd, BKGND_TILENUMBER, temp );
return 0;
}
case BKGND_FINDFILE: {
CHAR title[] = "FileBar - Find A Background Image";
ULONG s;
HWND hwndDialog;
fileDlgInfo.fl = FDS_OPEN_DIALOG|FDS_CENTER;
fileDlgInfo.pszTitle = title;
strcat(fileDlgInfo.szFullFile, "*.BMP\0");
hwndDialog = WinFileDlg( HWND_DESKTOP, hWnd, &fileDlgInfo );
if (hwndDialog && (fileDlgInfo.lReturn == DID_OK)) {
strcpy( backgroundBitmap, fileDlgInfo.szFullFile );
s=0;
while(fileDlgInfo.szFullFile[s]!='\0')
s++;
while((fileDlgInfo.szFullFile[s]!='\\') && (s>=0))
s--;
if (fileDlgInfo.szFullFile[s]=='\\')
fileDlgInfo.szFullFile[s+1]='\0';
else
fileDlgInfo.szFullFile[0]='\0';
WinSetDlgItemText( hWnd, BKGND_BITMAPNAME, backgroundBitmap );
}
else
fileDlgInfo.szFullFile[0]='\0';
return 0;
}
}
}
//----------------------------------------------------------------------
// if nothing further we want to intercept, pass message onto system
//----------------------------------------------------------------------
default:
return WinDefDlgProc( hWnd, msg, mp1, mp2 );
}
}